0

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;
        }
}
Lwin Htoo Ko
  • 2,326
  • 4
  • 26
  • 38
  • So far, it is because of nginx server in staging server. – Lwin Htoo Ko Sep 14 '21 at 14:52
  • It is because of Laravel application in staging server. When traffic comes to default URL, it redirects to /login and it also changes domain to IP. When I directly enter domain/login, browser keeps the domain. – Lwin Htoo Ko Sep 14 '21 at 14:56

1 Answers1

0

I got it was because of Laravel Application.

There is default redirect to login page when user has not logged in. That is why my Laravel application redirects to /login URL however app keeps using private IP instead of domain name. I need to use proxy URL in the routes/web.php instead of using default.

Refer to this answer for Laravel Application with Reverse Proxy -> Laravel routes behind reverse proxy showing wrong url

I got some more grey hair now. :)

Lwin Htoo Ko
  • 2,326
  • 4
  • 26
  • 38