nginx try_files and Wordpress

Hi everyone,

I am having some difficulty with try_files under nginx. I followed this guide for setting up nginx with PHP and MySQL - https://www.linode.com/docs/websites/le … n-7-wheezy">https://www.linode.com/docs/websites/lemp/lemp-server-on-debian-7-wheezy

I have a Wordpress blog (in this post I have changed it to example.com for privacy reasons) and it looks like this:

server {
    listen   80;
    server_name www.example.com example.com;
    access_log /srv/www/example.com/logs/access.log;
    error_log /srv/www/example.com/logs/error.log;

    location / {
        root   /srv/www/example.com/public_html;
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
      try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public_html$fastcgi_script_name;
    }

}

Could anyone please tell me how the try_files should be? When I attempt to load the website it simply returns 404. I haven't used nginx in a few years thus any help would be kindly appreciated :-)

Cheers

6 Replies

Helping you while you hide information is going to be like pulling teeth.

What is the domain that is actually experiencing this issue?

  • Les

I do not see why you need the domain name - it is a simple wordpress setup and that is the config file as above

You also "don't see why" your site isn't working.

No one likes to play twenty-questions.

Is your website private? No? Then if it's public, what difference does it make if you list it here or not?

You just need this inside the "location /" block:

 location / {
   [...]
    try_files $uri $uri/ /index.php?$args;
  }

@vonskippy:

You also "don't see why" your site isn't working.

No one likes to play twenty-questions.

Is your website private? No? Then if it's public, what difference does it make if you list it here or not?

I'm sorry you feel that way.

@sanvila:

You just need this inside the "location /" block:

 location / {
   [...]
    try_files $uri $uri/ /index.php?$args;
  }

Thanks! It worked!

this did work, thanks

 location / {
   [...]
    try_files $uri $uri/ /index.php?$args;
  }

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct