Skip to content

Commit

Permalink
feat: nginx adventures #4 - fixed ssl error
Browse files Browse the repository at this point in the history
  • Loading branch information
akifisitan committed May 12, 2024
1 parent 222a880 commit 14dbab6
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ FROM nginx:latest
# Remove the default Nginx configuration
RUN rm /etc/nginx/conf.d/default.conf

# Copy the custom Nginx configuration files
# Copy config file
COPY nginx.conf /etc/nginx/nginx.conf

# Copy proxy settings
COPY proxy_settings.conf /etc/nginx/conf.d/proxy_settings.conf
# Copy shared proxy settings
COPY location_proxy_shared.conf /etc/nginx/conf.d/location_proxy_shared.conf

# Copy microservice related
COPY service_config/auth_service_routes.conf /etc/nginx/conf.d/auth_service.conf
Expand All @@ -17,4 +17,3 @@ COPY service_config/user_service_routes.conf /etc/nginx/conf.d/user_service.conf

# Expose port 80
EXPOSE 80

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# proxy_settings.conf
# location_proxy_shared.conf
proxy_pass_request_headers on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

# nginx.conf
events {
worker_connections 1024;
}

http {

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
##
# Basic Settings
##

sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

default_type application/json;
##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

upstream auth_service {
server ovtf-auth-srv-clpiqqqcgq-ew.a.run.app:443;
Expand All @@ -32,6 +67,5 @@ http {
include /etc/nginx/conf.d/auth_service.conf;
include /etc/nginx/conf.d/recommendation_service.conf;
include /etc/nginx/conf.d/user_service.conf;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
location /users/create-user/ {
proxy_pass https://auth_service;
proxy_set_header Host $auth_service_host;
include /etc/nginx/conf.d/proxy_settings.conf;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/login/ {
proxy_pass https://auth_service;
proxy_set_header Host $auth_service_host;
include /etc/nginx/conf.d/proxy_settings.conf;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
location /users/recommend-you-might-like/ {
proxy_pass https://recommendation_service;
proxy_set_header Host $recommendation_service_host;
include /etc/nginx/conf.d/proxy_settings.conf;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/recommend-since-you-like/ {
proxy_pass https://recommendation_service;
proxy_set_header Host $recommendation_service_host;
include /etc/nginx/conf.d/proxy_settings.conf;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/recommend-friend-mix/ {
proxy_pass https://recommendation_service;
proxy_set_header Host $recommendation_service_host;
include /etc/nginx/conf.d/proxy_settings.conf;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/recommend-friend-listen/ {
proxy_pass https://recommendation_service;
proxy_set_header Host $recommendation_service_host;
include /etc/nginx/conf.d/proxy_settings.conf;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
location /users/get-user-profile/ {
proxy_pass https://user_service;
proxy_set_header Host $user_service_host;
include /etc/nginx/conf.d/proxy_settings.conf;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/edit-user-preferences/ {
proxy_pass https://user_service;
proxy_set_header Host $user_service_host;
include /etc/nginx/conf.d/proxy_settings.conf;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/delete-user/ {
proxy_pass https://user_service;
proxy_set_header Host $user_service_host;
include /etc/nginx/conf.d/proxy_settings.conf;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}
26 changes: 26 additions & 0 deletions ovatify-backend/microservices/api-gateway/vm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
copy:
sudo cp nginx.conf /etc/nginx/nginx.conf
sudo cp location_proxy_shared.conf /etc/nginx/conf.d/location_proxy_shared.conf
sudo cp service_config/auth_service_routes.conf /etc/nginx/conf.d/auth_service.conf
sudo cp service_config/recommendation_service_routes.conf /etc/nginx/conf.d/recommendation_service.conf
sudo cp service_config/user_service_routes.conf /etc/nginx/conf.d/user_service.conf
sudo nginx -t
sudo systemctl reload nginx

update:
sudo cp proxy.conf /etc/nginx/sites-available/proxy.conf
sudo cp nginx.conf /etc/nginx/nginx.conf
sudo nginx -t
sudo systemctl reload nginx

reload:
sudo systemctl reload nginx

check:
sudo nginx -t

view-error-logs:
sudo tail -f /var/log/nginx/error.log

view-access-logs:
sudo tail -f /var/log/nginx/access.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# location_proxy_shared.conf
proxy_pass_request_headers on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
75 changes: 75 additions & 0 deletions ovatify-backend/microservices/api-gateway/vm/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

# nginx.conf
events {
worker_connections 1024;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# Upstream

upstream auth_service {
server ovtf-auth-srv-clpiqqqcgq-ew.a.run.app:443;
}

upstream recommendation_service {
server recommendation-service-clpiqqqcgq-ew.a.run.app:443;
}

upstream user_service {
server user-service-clpiqqqcgq-ew.a.run.app:443;
}

# Reverse proxy server

server {
listen 80;

set $auth_service_host ovtf-auth-srv-clpiqqqcgq-ew.a.run.app;
set $recommendation_service_host recommendation-service-clpiqqqcgq-ew.a.run.app;
set $user_service_host user-service-clpiqqqcgq-ew.a.run.app;

include /etc/nginx/conf.d/auth_service.conf;
include /etc/nginx/conf.d/recommendation_service.conf;
include /etc/nginx/conf.d/user_service.conf;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# auth_service_routes.conf
location /users/create-user/ {
proxy_pass https://auth_service;
proxy_set_header Host $auth_service_host;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/login/ {
proxy_pass https://auth_service;
proxy_set_header Host $auth_service_host;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# recommendation_service_routes.conf
location /users/recommend-you-might-like/ {
proxy_pass https://recommendation_service;
proxy_set_header Host $recommendation_service_host;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/recommend-since-you-like/ {
proxy_pass https://recommendation_service;
proxy_set_header Host $recommendation_service_host;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/recommend-friend-mix/ {
proxy_pass https://recommendation_service;
proxy_set_header Host $recommendation_service_host;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/recommend-friend-listen/ {
proxy_pass https://recommendation_service;
proxy_set_header Host $recommendation_service_host;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# user_service_routes.conf
location /users/get-user-profile/ {
proxy_pass https://user_service;
proxy_set_header Host $user_service_host;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/edit-user-preferences/ {
proxy_pass https://user_service;
proxy_set_header Host $user_service_host;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

location /users/delete-user/ {
proxy_pass https://user_service;
proxy_set_header Host $user_service_host;
include /etc/nginx/conf.d/location_proxy_shared.conf;
}

0 comments on commit 14dbab6

Please sign in to comment.