1

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

}

2 Answers 2

1

Move index index.php; out of the location / block into the server block.

Your config should look like this :

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

You can omit the location / block because it isn't needed in your case.

Edit: In cases such as this, tail /var/log/nginx/error.log will help you to pinpoint what is going wrong. In you case, it will probably show :

    directory index of "/srv/www/mydomain.com/public_html/myWordpressDir/wp-admin/" is forbidden
0

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.

1
  • I tried that before, and all it did was change from a 403 error to say 'No input file specified.'
    – WebDevDude
    Dec 2, 2012 at 0:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .