Nginx Config – I can't access WordPress admin area

WebDevDude asked:

I am a complete noob when it comes to Nginx, but I’m trying to make the switch over for my WordPress site. Everything works, even the permalink, but I can’t access my WordPress admin directory (I get a 403 error).

I have my WordPress install in a subfolder, so that complicates things a bit for me. Here is my Nginx config file:

server {
access_log /srv/www/;
error_log /srv/www/;
root /srv/www/;

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_index index.php;
    fastcgi_param SCRIPT_FILENAME /srv/www/$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;


My answer:

You’re missing an index declaration. Example:

index index.php;

You have one in one location, but not the other. Therefore you can’t access index.php using / in that directory or subdirectories thereof.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.