【发布时间】:2013-01-30 01:18:21
【问题描述】:
我有一个在 Vagrant 开发环境中运行的 Wordpress 网站。当我加载http://localhost:8080 时,该网站正常运行,但一旦我尝试通过转到http://localhost:8080/wp-admin 来访问管理员,我就会被重定向到http://localhost/wp-admin/。
这里有两件事:
- 某些东西(Wordpress?)正在强制使用尾部斜杠(这很好,除了...)。
- 在尾部斜杠重定向中,端口丢失(这很不正常)。
我尝试添加 port_in_redirect 指令(老实说,使用这两个值),我在其他类似问题的答案中看到过,但它没有任何改变。这似乎是一个 Wordpress,咳咳,功能,但我找不到任何东西来解释它的目的或帮助我防止它破坏东西。我希望有人可以提供帮助。
我的 Nginx server 块:
server {
listen 80;
server_name localhost;
root /vagrant/www;
index index.php;
access_log /var/log/nginx/project.vm.access.log;
error_log /var/log/nginx/project.vm.error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests so the admin interface
# works correctly. I've tried with and without this. No difference.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
# Cache static files
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location = /favicon.ico {
access_log off;
log_not_found off;
}
location = /robots.txt {
access_log off;
log_not_found off;
allow all;
}
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
location ~ ~$ {
access_log off;
log_not_found off;
deny all;
}
}
在我的wp-config.php 文件中,我设置了WP_HOME 和WP_SITEURL 常量。
define('WP_HOME','http://localhost:8080');
define('WP_SITEURL','http://localhost:8080');
知道我错过了什么吗?
【问题讨论】:
-
如果是 Nginx 做的,请尝试在 wp-admin 重写中包含
server_port:rewrite /wp-admin$ $scheme://$host:$server_port$uri/ permanent; -
前几天我试过了。没有喜悦。谢谢。
-
帮助了我@myanimal。它在官方 WP nginx 文档中codex.wordpress.org/Nginx