![](/img/trans.png)
[英]Wordpress Permalinks return 404 when using NGINX as a reverse proxy to apache
[英]Redirect to 127.0.0.1 when access a wordpress hosted with apache and nginx in proxy
我在 Apache2 上托管了一個 wordpress,前面有 Nginx。 <WORLD> ===> <NGINX PROXY> --> APACHE/DOCKER/STATIC WEBSITE etc...
我的 wordpress 代理的 nginx conf 是:
server {
server_name dev-www.example.com;
location / {
proxy_pass http://127.0.0.1:13400;
}
}
我的 apache 配置:
Listen 13400
<VirtualHost 127.0.0.1:13400>
CustomLog /var/log/httpd/sites/dev-www/access_log combined
ErrorLog /var/log/httpd/sites/dev-www/error_log
DirectoryIndex index.php
DocumentRoot /var/www/sites/example.com/dev-www
RewriteEngine On
<Directory /var/www/sites/example.com/dev-www/>
Options Indexes FollowSymLinks
AllowOverride all
</Directory>
</VirtualHost>
和 wordpress .htaccess
:
# 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
問題是當我繼續訪問dev-www.example.com/foobar.php
我被重定向到127.0.0.1/foobar.php
。 我知道它是從nginx
配置127.0.0.1
彈出來的,怎么解決?
我嘗試代理傳遞給dev-www.example.com:13400
但我得到了一個無限循環:
[2016 年 5 月 10 日星期二 23:44:45.001680] [core:error] [pid 1096] [client 127.0.0.1:54887] AH00124:由於可能的配置錯誤,請求超出了 10 個內部重定向的限制。 如有必要,請使用“LimitInternalRecursion”來增加限制。 使用“LogLevel debug”獲取回溯。,參考: http : //dev-www.example.com/
注意: http://dev-www.example.com
: http://dev-www.example.com
或http://dev-www.example.com/index.php
沒有問題 謝謝。
注意2:如果我將 nginx 配置更改為 localhost:13400,那么我將被重定向到 localhost/login-3。 它看起來像 .htaccess 重定向到 ServName 並且它是 127.0.0.1
它是 wordpress 重定向到HTTP_HOST
,添加
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
在wp-config.php
修復它。
聽起來就像您已將 wordpress 站點從本地開發系統導出到生產系統一樣。 您很可能也無法再進入 /wp-admin 了。 在這種情況下,您必須手動更新表wp_options
的數據庫條目。 尋找選項siteurl
和home
。
也請嘗試將此添加到 wp-config.php (但我擔心,這僅針對傳出請求)
define('WP_PROXY_HOST', '1.2.3.4');
define('WP_PROXY_PORT', '13400');
# define('WP_PROXY_USERNAME', 'my_user_name');
# define('WP_PROXY_PASSWORD', 'my_password');
define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');
對於 Nginx,您必須確保 Host 標頭設置正確,您的示例應該是:
server {
server_name dev-www.example.com;
location / {
proxy_set_header Host dev-www.example.com;
proxy_pass http://127.0.0.1:13400;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.