nginx proxy_pass到另一个服务器/路径/

时间:2017-04-11 10:47:50

标签: wordpress nginx reverse-proxy

我有2台Ubuntu 16.04服务器:一台反向代理服务器(有公共IP和本地IP 192.168.1.xxx)和一台Web服务器(只有本地IP 192.168.1.xxx)。

在反向代理服务器上,我安装了nginx,configured it如下:

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

        server_name mysite1.com www.mysite1.com;

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

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

        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.1.xxx/wordpress1/;
                proxy_ssl_session_reuse off;
                proxy_set_header Host $http_host;
                proxy_cache_bypass $http_upgrade;
                proxy_redirect off;
        }


}

在Web服务器上,我安装了LEMP堆栈。 / etc / nginx / sites-available / default的内容为:

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;
    }
}

因为我想在一个Web服务器上提供更多网站,例如 https://mysite1.com/位于/ opt / wordpress1 /, https://mysite2.com/位于/ opt / wordpress2 / 等等... 所以我创建了符号链接并将这些目录的所有者更改为www-data

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

但是,当我转到https://mysite1.com时,会转到https://mysite1.com/wordpress1/ 结果是404 Not Found nginx / 1.10.0(Ubuntu)。

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

希望这有帮助。