skip to Main Content

We have wordpress installedin a subdirectory on our NGINX server. We want our blog URL to look something like www.example.com/blog. Individual blog posts urls should be like www.example.com/blog/post-name. For this when we go to setting->permalinks menu in wordpress and change it to Post Name from Default, it starts giving error. But it works just fine when we leave it default (www.example.com/blog/?p=123).
Blog directory is installed under html folder in nginx.
We’ve made following entry in nginx.conf file:

location /blog {

root /usr/share/nginx/html;
index index.html index.php;
try_files $uri $uri/ /index.php?$args;

location ~ .php$ {
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass   127.0.0.1:9000;
}
}

blog directory is installed at same level as the folder for our main site (example.com).
What are we doing wrong?

2

Answers


  1. Try this,

    location /blog/ {
        root /usr/share/nginx/html;
        index index.html index.php;
        try_files $uri $uri/ /blog/index.php?$args;
    }
    
    Login or Signup to reply.
  2. Had a similar issue and I added this in my nginx conf to make it work for wordpress /index.php/permalink urls in nginx hhvm 3.21

    Adding this for everyone’s reference:

    location / {
    
        ...
        fastcgi_param  SCRIPT_FILENAME $document_root/index.php$fastcgi_script_name;
    
    
    }
    

    or

    location / {
    
        rewrite ^/([^.]+)$ /index.php/$1 break;
    
    }
    

    Ensure you are using a fastcgi and not a server version (in server version you may get too many redirects due to rewrite)

    • TESTED
    • QA PASSED
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search