Nginxconfiguration – 我无法访问WordPresspipe理区域

对于Nginx来说,我是一个完整的noob,但是我正在尝试切换到我的WordPress站点。 一切正常,甚至永久链接,但我不能访问我的WordPresspipe理目录(我得到一个403错误)。

我有我的WordPress安装在一个子文件夹,所以使我的一些事情复杂一点。 这是我的Nginxconfiguration文件:

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; } 

}

移动index index.php; 出了location /块到服务器块。

你的configuration应该是这样的:

 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 

你错过了一个index声明。 例:

 index index.php; 

你在一个location有一个,但不是另一个。 因此,你不能通过在该目录或其子目录中使用/来访问index.php