I have 2 servers. One has public IP and open to internet. That is used as production server. Another server is used as staging server.
mydomain.com is pointed to production server and it works fine. What I want to achieve is staging-backend.mydomain.com is pointed to production server and nginx in production server should do forwarding to staging server.
when user browses staging-backend.mydomain.com, traffic hits to production server nginx and then it relays all traffic between staging server and user.
I tried below configuration but URL in browser changes to private IP whenever I entered staging-backend.mydomain.com in web browser. I want to keep staging-backend.mydomain.com as URL in web browser and make staging web available.
upstream staging {
server 192.168.1.100:443;
}
server {
listen 80;
server_name staging-backend.mydomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name staging-backend.mydomain.com;
ssl_certificate /var/www/project/ssl_certs/__mydomain_com.chain.crt;
ssl_certificate_key /var/www/project/ssl_certs/__mydomain_com.key;
access_log /var/log/nginx/staging_backend.access.log;
error_log /var/log/nginx/staging_backend.error.log;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass https://staging$request_uri;
}
}