【发布时间】:2015-08-11 22:46:52
【问题描述】:
我正在尝试在 /blog 上托管一个 wordpress。我使用 Nginx 作为代理和 Apache 来运行 Wordpress。我认为我非常接近一个可行的解决方案。
我现在面临的唯一问题是去 /blog/wp-admin 加载 wordpress 仪表板,但随后有些事情正在重写或重定向到 /wp-admin。前端页面没问题,例如:/blog/2015/05/28/hello-world/。
如何确定是谁将仪表板网址从 www.example.com/blog/wp-admin 重写为 www.example.com/wp-admin/ ?
这是我的 Nginx 配置:
upstream app_node {
server 127.0.0.1:3000;
}
upstream app_wordpress {
server 127.0.0.1:8080;
}
server {
listen 0.0.0.0:80;
server_name example.com;
access_log /var/log/nginx/node.log;
error_log /var/log/nginx/node.error.log debug;
#port_in_redirect off;
rewrite_log on;
client_max_body_size 50M;
# pass the request to the node.js server with the correct headers
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_node/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location ~ ^\/blog(.*)$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080$1;
proxy_redirect off;
}
Apache 配置:
<VirtualHost *:8080>
ServerName example.com:8080
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LogLevel alert rewrite:trace6
</VirtualHost>
Wordpress htaccess(wordpress 文件位于 /var/www/html):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
【问题讨论】:
-
这可能是 wordpress 不理解它植根于
/blog,所以它返回一个/的链接。你为什么在这里使用 Apache 和 nginx?仅 Apache 就完全能够将 wp 安装的根目录放在/blog并代理到您的节点应用程序。 -
我发现有一些javascript重写了窗口位置example.com/wp-admin" />。这是来自 wp-admin/includes/misc.php。如果我删除它,它可以工作,但我看到 jquery 没有加载。我从一开始就想要 nginx,现在我在 nginx 后面使用 apache,因为它适用于 wordpress。