Nginx Proxy
Introduction
Nginx.conf
Currently, we have two servers:
- Image File server sitting at localhost:8000
- Pair User server sitting at localhost:8888
We use nginx to proxy the traffic to the correct server. Also in the future, we can add support of multiple server and machine rather than a single machine. Note for ssl connections like https and wss, some extra configuration is required. Meanwhile, unlike HTTP, WebSocket needs some extra parameters to upgrade as well.
server {
listen 80;
server_name ccyy.xyz;
location / {
proxy_pass http://localhost:9000;
}
location /api/v2/ {
proxy_pass http://localhost:8000;
}
location /api/v1/ {
proxy_pass http://localhost:8000;
}
location /api/v0/ {
proxy_pass http://localhost:8000;
}
location /api/v3/ {
proxy_pass http://localhost:8888;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_connect_timeout 10s;
proxy_read_timeout 3600s;
}
}
server {
listen 443;
server_name ccyy.xyz;
ssl_certificate /root/ccyy.xyz/Nginx/1_ccyy.xyz_bundle.crt;
ssl_certificate_key /root/ccyy.xyz/Nginx/2_ccyy.xyz.key;
ssl on;
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://localhost:9000;
}
location /api/v2/ {
proxy_pass http://localhost:8000;
}
location /api/v1/ {
proxy_pass http://localhost:8000;
}
location /api/v0/ {
proxy_pass http://localhost:8000;
}
location /api/v3/ {
proxy_pass http://localhost:8888;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_connect_timeout 10s;
proxy_read_timeout 3600s;
}
}