我正在面对一个类似的问题,在这里我使用Nginx作为运行WordPress的Apache服务器(Ubuntu)的代理。 网站的内部链接都给301本地主机redirect。
例如,链接: wwww.example.com/internal-linkredirect到localhost/internal-link ,它给出了错误404。
Apache的configuration如下:
<VirtualHost *:80> <Directory /var/www/html> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all Require all granted </Directory> ServerAdmin [email protected] ServerName example.com ServerAlias www.example.com ServerAlias *.example.com DocumentRoot /var/www/html ...
Nginxconfiguration文件如下:
server { # Where IP is server IP and example is the domain name listen IP:80; server_name static.example.com; location / { proxy_pass http://localhost:8480; proxy_set_header X-Real-IP $remote_addr; } } server { listen IP:80; server_name example.com; rewrite ^ $scheme://www.example.com$request_uri redirect; } server { listen IP:80; # your server's public IP address server_name www.example.com; # your domain name location / { proxy_pass http://localhost:8020; proxy_set_header X-Real-IP $remote_addr; } }
.htaccess是由WordPress生成的默认值:
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
以下是Apache访问日志的一些logging:
10.0.2.2 - - [15/Jul/2016:07:11:31 -0400] "GET /link/ HTTP/1.0" 301 335 "-" "Mozilla/5.0 (compatible; Cliqzbot/1.0 +http://cliqz.com/company/cliqzbot)" 10.0.2.2 - - [15/Jul/2016:07:08:02 -0400] "GET /link/ HTTP/1.0" 404 5396 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0)
任何想法是什么导致这个以及如何解决它?
我使用下面的NGINX服务器模块对本地Apache HTTP Server的所有请求进行proxy_pass :
# cat /usr/local/etc/nginx/conf.d/apache24.conf server { listen 80; location / { proxy_pass http://127.0.0.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Real-IP $remote_addr; proxy_pass_header server; } } #
和Apache的HTTP Server VirtualHostconfiguration正常的方式。