Skip to content

Instantly share code, notes, and snippets.

@sheharyarn
Created May 8, 2020 17:45
Show Gist options
  • Save sheharyarn/e86dfc3f2eb0017991f86c57673517d5 to your computer and use it in GitHub Desktop.
Save sheharyarn/e86dfc3f2eb0017991f86c57673517d5 to your computer and use it in GitHub Desktop.
Multi subdomain local website Nginx config
# Dev Local Conf for multiple subdomain websites
# Here `appdev.com` is pointing to 127.0.0.1
#resolver 127.0.0.11 valid=5s; # for docker
ssl_certificate /usr/local/etc/nginx/ssl/app.server.crt;
ssl_certificate_key /usr/local/etc/nginx/ssl/app.server.key;
upstream app_backend { server localhost:4000; }
upstream app_website { server localhost:5001; }
upstream app_storybook { server localhost:9090; }
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name www.appdev.com;
return 302 $scheme://appdev.com$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name appdev.com;
location / {
proxy_pass http://app_website;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name storybook.appdev.com;
location / {
proxy_pass http://app_storybook;
}
}
server {
listen 80;
listen 443 ssl;
listen [::]:80;
listen [::]:443 ssl;
server_name *.appdev.com;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header Referrer-Policy "strict-origin-when-cross-origin";
add_header X-App-Server $upstream_addr always;
set $cors_origin 'https://appdev.com';
include utils/cors.conf; # from: https://gist.github.com/jprjr/1a723b18335bcc455ac5
if ($scheme = 'http') {
return 302 https://$host$request_uri;
}
location / {
proxy_pass https://app_backend;
proxy_http_version 1.1;
proxy_set_header upgrade $http_upgrade;
proxy_set_header connection "upgrade";
proxy_set_header x-real-ip $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header host $http_host;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment