我对 Nginx 完全是菜鸟,但我正在尝试为我的 WordPress 网站切换。一切正常,甚至永久链接也是如此,但我无法访问我的 WordPress 管理目录(出现 403 错误)。
我的 WordPress 安装在子文件夹中,因此对我来说事情有点复杂。这是我的 Nginx 配置文件:
server {
server_name mydomain.com;
access_log /srv/www/mydomain.com/logs/access.log;
error_log /srv/www/mydomain.com/logs/error.log;
root /srv/www/mydomain.com/public_html;
location / {
index index.php;
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location /myWordpressDir {
try_files $uri $uri/ /myWordpressDir/index.php?$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/mydomain.com/public_html$fastcgi_script_name;
fastcgi_split_path_info ^(/myWordpressDir)(/.*)$;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
}
}
答案1
index index.php;
从块中移出location /
并进入服务器块。
你的配置看起来应该像这样:
server {
server_name mydomain.com;
access_log /srv/www/mydomain.com/logs/access.log;
error_log /srv/www/mydomain.com/logs/error.log;
root /srv/www/mydomain.com/public_html;
index index.php;
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
# try_files $uri $uri/ /index.php?$args;
}
location /myWordpressDir {
try_files $uri $uri/ /myWordpressDir/index.php?$args;
}
您可以省略该location /
块,因为您的例子中不需要它。
编辑:在这种情况下,tail /var/log/nginx/error.log
将帮助您查明问题所在。 在您的案例中,它可能会显示:
directory index of "/srv/www/mydomain.com/public_html/myWordpressDir/wp-admin/" is forbidden
答案2
您缺少index
声明。例如:
index index.php;
您在一个目录中有一个location
,但没有另一个。因此您无法在该目录或其子目录中index.php
使用。/