nginx proxy_pass to another server/path/

I have 2 Ubuntu 16.04 servers: one reverse proxy server (has public IP and local IP 192.168.1.xxx) and one web server (has only local IP 192.168.1.xxx).

On reverse proxy server I installed nginx, and configured it as follow:

server {
        listen 80;
        #listen [::]:80 ipv6only=on;

        server_name mysite1.com www.mysite1.vn;

        return 301 https://$host$request_uri;
}

server {
        listen 443;
        server_name mysite1.com www.mysite1.vn;

        ssl on;
        # Use certificate and key provided by Let's Encrypt:
        ssl_certificate /etc/letsencrypt/live/mysite1.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/mysite1.com/privkey.pem;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://192.168.x.x/wordpress/;
                proxy_ssl_session_reuse off;
                proxy_set_header Host $http_host;
                proxy_cache_bypass $http_upgrade;
                proxy_redirect off;
        }


}

On web server I installed LEMP stack. The content of /etc/nginx/sites-available/default is:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.php index.html index.htm;
    server_name _;
    location / {
        try_files $uri $uri/ =404;
    }
    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
    location ~ /.ht {
        deny all;
    }
}

Because I want serve more website on one web server such as
https://mysite1.com/ is at /opt/wordpress1/ ,
https://mysite2.com/ is at /opt/wordpress2/
etc…
so I made symbolic links and changed owner of these directories to www-data

sudo ln -s /opt/wordpress/ /var/www/html/
sudo chown -R www-data:www-data /opt/wordpress1/
sudo chown -R www-data:www-data /var/www/html/

However, when I go to https://mysite1.com, it goes to https://mysite1.com/wordpress1/
and the result is 404 Not Found nginx/1.10.0 (Ubuntu).

How can I fix this problem?

Read more here: nginx proxy_pass to another server/path/

Leave a Reply

Your email address will not be published. Required fields are marked *