I want to setup a WordPress blog, but not with a typical configuration:

  • The main site is at www.example.com. As of now, it just has a static index.html file with an image, we will use probably an index.php to show some information and access to a premium part of the site

  • The blog, with WordPress, at www.example.com/blog

I am setting this up under Nginx, but although I have been able to see both my static homepage at www.example.com and my blog at www.example.com/blog, I can't access the WordPress' admin panel, so I can't login or write new posts.

This is the /etc/nginx/sites-enabled/www.example.com configuration file:

server {
    server_name  www.example.com;
    rewrite ^(.*) http://example.com$1 permanent;

server {
   listen   80;
   server_name  example.com;

   access_log  /var/www/www.example.com/log/access.log;
   error_log      /var/www/www.example.com/log/error.log info;

   index index.php;

   location / {
        set $php_root /var/www/www.example.com;
        try_files $uri $uri/ /index.php?q=$uri&$args;

   location /blog {
        set $php_root /var/www/www.example.com;
        try_files $uri $uri/ /blog/index.php?q=$uri&$args;

   ## Images and static content is treated differently

   location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|\
rtf|js)$ {
         access_log        off;
         expires           30d;
         root /var/www/www.example.com;

    location ~* \.php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $php_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     on;
        fastcgi_read_timeout 180;


    ## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
        deny  all;
upstream backend {


What must I do to be able to access the admin panel? I guess it has something to do with the php location, but now sure what to touch :(

| improve this question | | | | |

This shouldn't work at all for any PHP. You set a variable in one location and then use it in another, that doesn't work in Nginx. The scope inherits downwards only, not upwards or across, so http -> server -> location, never location -> location.

Besides that, there's no need to actually use a custom variable for PHP root, you should just specify your root with the normal root directive (in the server context) and then use the built-in variable $document_root for your SCRIPT_FILENAME fastcgi param.

| improve this answer | | | | |
  • What you are saying is that I need to create another server->location instance on my config file? I'm doing this because I've seen examples across the Internet that seemed to do that to what I was looking for. The $php_root variable was also taken from one of those examples, but using the real root folder will be no problem. – javipas Feb 9 '11 at 9:03
  • With Nginx you really don't want to use examples across the Internet, there are very few resources with solid information from people who didn't convert from Apache just yesterday. The best one is definitely the wiki. I'm not sure what you mean by server->location instance but see here for a thorough Wordpress documentation: wiki.nginx.org/Wordpress – Martin Fjordvald Feb 9 '11 at 13:00
  • Thx for the suggestion. I've read the wiki, and there are several locations inside the same server, as my config file shows... so now I'm not entirely sure I understood your answer. What did you mean when talking about "http->server->location..."? – javipas Feb 9 '11 at 23:14
  • by http->server->location I'm talking about how Nginx uses directives. Something specified in your server block is available in all location blocks while something specified in a location block is only available in that one location block. Could you update your post with your latest configuration file? That makes it easier to follow what you've done. – Martin Fjordvald Feb 10 '11 at 10:03

To fix this configuration, set a root directive in the server block:

root /var/www/www.example.com;

Then use the $document_root in your fastcgi_param:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

The set $php_root calls can be removed. As @MartinFjordvald noted, they don't do anything anyway.

| improve this answer | | | | |
  • thanks for the answer Michael... I'm affraid I don't even remember what I wanted to do with this, but that idea never came to a real blog. Anyway, your answer seems to confirm @MartinFjorvald 's one, so I'll take his like the good one if you don't mind. Regards. – javipas Aug 1 '12 at 15:57
  • In hindsight, I probably should have edited his answer... :) – Michael Hampton Aug 1 '12 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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