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 {
server 127.0.0.1:9000;
}
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 :(
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.
To fix this configuration, set a
root
directive in theserver
block:Then use the
$document_root
in yourfastcgi_param
:The
set $php_root
calls can be removed. As @MartinFjordvald noted, they don't do anything anyway.