Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

}

share|improve this question

2 Answers 2

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
share|improve this 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.

share|improve this answer
    
I tried that before, and all it did was change from a 403 error to say 'No input file specified.' –  WebDevDude Dec 2 '12 at 0:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.