Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create nginx reverse proxy #95

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions configs/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
events {
worker_connections 1024; ## Default: 1024
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'$upstream_addr $upstream_response_time $request_time ';

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

upstream userservice {
server user-service:8001;
}
upstream publishservice {
server publish-service:8002;
}
upstream commentservice {
server comment-service:8003;
}
upstream favoriteservice {
server favorite-service:8004;
}
upstream relationservice {
server relation-service:8005;
}
upstream messageservice {
server message-service:8006;
}
server {
listen 80;
server_name nginx;

location /douyin/user/ {
proxy_method GET;
rewrite ^/douyin/user/(.*)$ /douyin/user$1 break;
proxy_pass http://userservice;
}
location /douyin/user/register/ {
proxy_method POST;
proxy_set_header Content-Type "application/json";
rewrite ^/douyin/user/register/(.*)$ /douyin/user/register$1 break;
proxy_pass http://userservice;
}
location /douyin/user/login/ {
proxy_method POST;
proxy_set_header Content-Type "application/json";
rewrite ^/douyin/user/login/(.*)$ /douyin/user/login$1 break;
proxy_pass http://userservice;
}
location /douyin/publish/action/ {
proxy_method POST;
rewrite ^/douyin/publish/action/(.*)$ /douyin/publish/action$1 break;
proxy_pass http://publishservice;
}
location /douyin/publish/list/ {
proxy_method GET;
rewrite ^/douyin/publish/list/(.*)$ /douyin/publish/list$1 break;
proxy_pass http://publishservice;
}
location /douyin/feed {
proxy_method GET;
proxy_pass http://publishservice;
}
location /douyin/favorite/list/ {
proxy_method GET;
rewrite ^/douyin/favorite/list/(.*)$ /douyin/favorite/list$1 break;
proxy_pass http://favoriteservice;
}
location /douyin/favorite/action/ {
proxy_method POST;
proxy_set_header Content-Type "application/json";
rewrite ^/douyin/favorite/action/(.*)$ /douyin/favorite/action$1 break;
proxy_pass http://favoriteservice;
}
location /douyin/relation/follow/list/ {
proxy_method GET;
rewrite ^/douyin/relation/follow/list/(.*)$ /douyin/relation/follow/list$1 break;
proxy_pass http://relationservice;
}
location /douyin/relation/follow/action/ {
proxy_method POST;
proxy_set_header Content-Type "application/json";
rewrite ^/douyin/relation/follow/action/(.*)$ /douyin/relation/follow/action$1 break;
proxy_pass http://relationservice;
}
location /douyin/relation/follower/list/ {
proxy_method GET;
rewrite ^/douyin/relation/follower/list/(.*)$ /douyin/relation/follower/list$1 break;
proxy_pass http://relationservice;
}
location /douyin/message/chat/ {
proxy_method GET;
rewrite ^/douyin/message/chat/(.*)$ /douyin/message/chat$1 break;
proxy_pass http://messageservice;
}
location /douyin/message/action/ {
proxy_method POST;
rewrite ^/douyin/message/action/(.*)$ /douyin/message/action$1 break;
proxy_set_header Content-Type "application/json";
proxy_pass http://messageservice;
}
location /douyin/comment/list/ {
proxy_method GET;
rewrite ^/douyin/comment/list/(.*)$ /douyin/comment/list$1 break;
proxy_pass http://commentservice;
}
location /douyin/comment/action/ {
proxy_method POST;
rewrite ^/douyin/comment/action/(.*)$ /douyin/comment/action$1 break;
proxy_set_header Content-Type "application/json";
proxy_pass http://commentservice;
}
}
}
36 changes: 24 additions & 12 deletions docker/service/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
version: "3"
services:
nginx:
image: nginx:1.24.0
container_name: nginx
restart: always
ports:
- "32796:80"
volumes:
- "../../configs/nginx/nginx.conf:/etc/nginx/nginx.conf"
- "../../_data/nginx/logs:/var/log/nginx"
networks:
- atreus_net
depends_on:
user-service:
condition: service_started
publish-service:
condition: service_started
comment-service:
condition: service_started
favorite-service:
condition: service_started
relation-service:
condition: service_started
message-service:
condition: service_started
mysql:
image: mysql/mysql-server:8.0.32
container_name: mysql
Expand Down Expand Up @@ -100,8 +124,6 @@ services:
container_name: user-service
privileged: true
restart: always
ports:
- "18001:8001"
networks:
- atreus_net
depends_on:
Expand All @@ -121,8 +143,6 @@ services:
container_name: publish-service
privileged: true
restart: always
ports:
- "18002:8002"
networks:
- atreus_net
depends_on:
Expand All @@ -142,8 +162,6 @@ services:
container_name: comment-service
privileged: true
restart: always
ports:
- "18003:8003"
networks:
- atreus_net
depends_on:
Expand All @@ -163,8 +181,6 @@ services:
container_name: favorite-service
privileged: true
restart: always
ports:
- "18004:8004"
networks:
- atreus_net
depends_on:
Expand All @@ -184,8 +200,6 @@ services:
container_name: relation-service
privileged: true
restart: always
ports:
- "18005:8005"
networks:
- atreus_net
depends_on:
Expand All @@ -205,8 +219,6 @@ services:
container_name: message-service
privileged: true
restart: always
ports:
- "18006:8006"
networks:
- atreus_net
depends_on:
Expand Down