example code of redirection
server {
if ($host = api.livewithtogether.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = api1.livewithtogether.com) {
return 301 https://$host$request_uri;
}
if ($host = livewithtogether.com) {
return 301 https://$host$request_uri;
}
if ($host = cms.livewithtogether.com) {
return 301 https://$host$request_uri;
}
listen 80 ;
listen [::]:80 ;
server_name api.livewithtogether.com livewithtogether.com cms.livewithtogether.com api1.livewithtogether.com;
return 404;
}
#for Dev
server{
listen 81;
server_name api.livewithtogether.com;
location / {
proxy_pass <http://127.0.0.1:3003>;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
}
}
#for Release
server {
# SSL configuration
#
# listen 443 ssl
server_name api.livewithtogether.com cms.livewithtogether.com api1.livewithtogether.com;
set $port 3000;
if ($host = cms.livewithtogether.com) {
set $port 3001;
set $pass_addr <http://127.0.0.1>;
}
if ($host = api.livewithtogether.com) {
set $port 3000;
set $pass_addr <http://127.0.0.1>;
}
if ($host = api1.livewithtogether.com) {
set $port 3002;
set $pass_addr <http://127.0.0.1>;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_pass $pass_addr:$port;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_redirect off;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/api1.livewithtogether.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/api.livewithtogether.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}