skip to Main Content

I have a server with multiple nginx instances

One of them is running at 8080

server {
    listen       8080;
    server_name  myip v2.example.com www.v2.example.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        proxy_pass  http://v2.example.com:8080/;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    
}

But I want to enter the site using example.com , instead of example.com:8080
Problem is that there is another server running at port 80 , I tried to fix it with the proxy pass, but it doesn’t seem to work

How can I fix that?

2

Answers


  1. You can try with ssl port 443. Of course you may need to add a valid ssl certificate to avoid error messages from the browser.

    If you do not want to use the above method, you can use the proxy pass on one of your other instances as follows:

    location /some-url/ {
        proxy_pass http://localhost:8080/;
    } 
    

    After that, You can then access it through: http://localhost:80/some-url/

    Login or Signup to reply.
  2. Redirect with return. You can put the following in one file:

    server {
        listen 80;
        listen [::]:80;
    
        server_name v2.example.com www.v2.example.com;
    
        return 301 http://$host$request_uri:8080;
    }
    
    server {
        listen       8080;
        server_name  myip v2.example.com www.v2.example.com;
    
        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search