I installed nginx and would like to setup wordpress as a final step. I followed many howtos but am unable to get it working.

The setup is fairly straightforward, the root dir of the webserver is /data/Sites/nkr1pt.homelinux.net. In that root dir I created a symlink to the wordpress folder in /usr/local/wordpress, so in fact all wordpress files can be accessed at /data/Sites/nkr1pt.homelinux.net/wordpress. Permissions are ok.

The plan is to get wordpress working at http://sirius/wordpress, the server's name is sirius. spawn-fcgi is running and listening on port 7777.

Here you can see the relevant config:

server {
    listen       80;
listen       8080;
    server_name  sirius;

root /data/Sites/nkr1pt.homelinux.net;
passenger_enabled on;
    passenger_base_uri /redmine;

    #charset koi8-r;

    #access_log  logs/access.log  main;

location ^~ /data {
   root /data/Sites/nkr1pt.homelinux.net;
   autoindex on;
   auth_basic "Restricted";
   auth_basic_user_file htpasswd;

    location ^~ /dump {
        root   /data/Sites/nkr1pt.homelinux.net;
        autoindex on;

location ^~ /wordpress {
       try_files $uri $uri/ /wordpress/index.php;

# pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
    #fastcgi_split_path_info ^(/wordpress)(/.*)$;
        fastcgi_pass   localhost:7777;
        #fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    #index     index.php;

please note that redmine, and the locations dump and data are working perfectly, it is only wordpress that I cannot get to work.

Can you please help me to the correct wordpress configuration in nginx? All help is much appreciated!

  • Remeber that Igor Sysoev (nginx author) strongly disagree with running apps on nginx. He is very taxative that nginx is to be used as a proxy between the outside and app servers. – coredump Feb 18 '11 at 21:18

I see that you include "fastcgi_params" in your nginx.conf after setting:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

If fastcgi_params overrides SCRIPT_FILENAME with something different, the previous line will be ignored and Wordpress won't work. I suggest that you invert the order of those two lines, like this:

include        fastcgi_params;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  • 1
    Calling index.php without any args is perfectly fine. WordPress supports this with no problem; it gets the args out of the FastCGI REQUEST_URI and QUERY_STRING parameters when called via FastCGI. The rest of your advice is sound; fastcgi_params should be included before overriding things that appear in it. – Michael Hampton Mar 27 '18 at 0:27
  • You are right, I tested without args and it works as well. Edited the answer accordingly. – Luca Gibelli Mar 27 '18 at 0:41

From what I've seen the main thing to get wordpress working is to translate the mod_rewrite rules into nginx format. The format is:

if (!-e $request_filename)
    rewrite ^(.+)$ /index.php?q=$1 last;

You are also missing

root /path/to/wordpress

In that subsection.

Otherwise, is there a particular error you are seeing? What do the error logs show?

  • I added the rewrite and root parts in location ~ \.php$ error.log gives no errors, when i try to load sirius/wordpress in the browser it shows a popup to download a BIN file; file content is php source from wordpress: define('WP_USE_THEMES', true); /** Loads the WordPress Environment and Template */ require('./wp-blog-header.php'); – nkr1pt Feb 18 '11 at 21:13
  • with editing and trying the nginx config file I also noticed 'input file is not specified' which seems to come from wordpress – nkr1pt Feb 18 '11 at 21:17

Use a server level rewrite. You should adjust all other locations. Oh and BTW, your setup is insecure. You should use a nested location or fastcgi_split_path_info. You can check my WP config on github for a nested location approach.

Anyway here's your request answered:

 rewrite ^ http://$host/wordpress$request_uri? permanent;

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.