Welcome! Log In Create A New Profile


nginx with subdomains on two servers

Posted by rifain 
nginx with subdomains on two servers
June 09, 2023 10:23AM
I have two servers: the first one has the IP address and is configured with the hostname hub.domain.tld. The DNS record is pointing to the public IP address, and all requests on ports 80 and 443 are forwarded to

The initial Nginx configuration on the first server was simple to set up and is functioning properly.

However, the issue arises with the second server, which is also configured with the Nginx as described below. The problem is that all requests made to vscode.domain.tld are being redirected to hub.domain.tld instead of

# /etc/nginx/sites-available/default

# top-level http config for websocket headers
# If Upgrade is defined, Connection = upgrade
# If Upgrade is empty, Connection = close
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;

# HTTP server to redirect all 80 traffic to SSL/HTTPS
server {
listen 80;
server_name vscode.domain.tld;

# Tell all requests to port 80 to be 302 redirected to HTTPS
return 302 https://$host$request_uri;

# HTTPS server to handle VS Code
server {
listen 443 ssl;
server_name vscode.domain.tld;

ssl_certificate /etc/letsencrypt/live/vscode.domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/vscode.domain.tld/privkey.pem;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
add_header Strict-Transport-Security max-age=15768000;

# Managing literal requests to the VS Code front end
location / {

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

# websocket headers
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Scheme $scheme;

proxy_buffering off;

# Managing requests to verify letsencrypt host
location ~ /.well-known {
allow all;

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 104
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready