[英]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). 我有2台Ubuntu 16.04服务器:一台反向代理服务器(具有公共IP和本地IP 192.168.1.xxx)和一台Web服务器(仅具有本地IP 192.168.1.xxx)。
On reverse proxy server I installed nginx, and configured it as follow: 在反向代理服务器上,我安装了nginx,并将其配置如下:
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;
}
}
On web server I installed LEMP stack. 在Web服务器上,我安装了LEMP堆栈。 The content of /etc/nginx/sites-available/default is:
/ 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;
}
}
Because I want serve more websites 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 因为我想成为一个网络服务器上的多个网站,如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/
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). 但是,当我转到https://mysite1.com时 ,它转到https://mysite1.com/wordpress1/ ,结果是404 Not Found nginx / 1.10.0(Ubuntu)。
How can I fix this problem? 我该如何解决这个问题?
First of all, seems like you are trying to do proxypass to serverb/wordpress on a server that has that wordpress install in its '/'. 首先,似乎您正在尝试对在其'/'中安装了wordpress的服务器上的serverb / wordpress执行proxypass。 I think you should also remove the '/' at the end of the proxy_pass sentence.
我认为您也应该在proxy_pass语句的末尾删除“ /”。
Second, have you search-replaced the URL in the Wordpress database? 其次,您是否已搜索替换了Wordpress数据库中的URL? Tool for that: [ https://interconnectit.com/products/search-and-replace-for-wordpress-databases/]
该工具:[ https://interconnectit.com/products/search-and-replace-for-wordpress-databases/]
Third, I see you're using https. 第三,我看到您正在使用https。 Have you modified the url accordingly and added the necessary modifications to wp-config.php for HTTPS - ProxyPass setup?
您是否已相应地修改了URL并为HTTPS-ProxyPass设置向wp-config.php添加了必要的修改? https://www.variantweb.net/blog/wordpress-behind-an-nginx-ssl-reverse-proxy/
https://www.variantweb.net/blog/wordpress-behind-an-nginx-ssl-reverse-proxy/
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.