Question

how to configure ngnix.config for wordpress ?[Permalink error] Using VestaCP - Ngnix php FPM

Hello. i am facing problem configuring ngnix.config block to support wordpress.

my wordpress shows 404 error when i put is to postname. others except plain text doesnt seems to be working.

after going through some doc , i figured that ngnix.config need modification to support .htaccess like behavior.

please can anyone check whats the problem?

server block is configured as below server { listen 139.59.10.214:80; server_name chetantest.tk www.chetantest.tk; root /home/admin/web/chetantest.tk/public_html; index index.php index.html index.htm; access_log /var/log/nginx/domains/chetantest.tk.log combined; access_log /var/log/nginx/domains/chetantest.tk.bytes bytes; error_log /var/log/nginx/domains/chetantest.tk.error.log error;

location / {

    location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
        expires     max;
    }

    location ~ [^/]\.php(/|$) {
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        if (!-f $document_root$fastcgi_script_name) {
            return  404;
        }

        fastcgi_pass    127.0.0.1:9003;
        fastcgi_index   index.php;
        include         /etc/nginx/fastcgi_params;
    }

    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;
    
    if ($scheme = http) {
           	return 301 https://$server_name$request_uri;
    }

}

error_page  403 /error/404.html;
error_page  404 /error/404.html;
error_page  500 502 503 504 /error/50x.html;

location /error/ {
    alias   /home/admin/web/chetantest.tk/document_errors/;
}

location ~* "/\.(htaccess|htpasswd)$" {
    deny    all;
    return  404;
}

location /vstats/ {
    alias   /home/admin/web/chetantest.tk/stats/;
    include /home/admin/web/chetantest.tk/stats/auth.conf*;
}

include     /etc/nginx/conf.d/phpmyadmin.inc*;
include     /etc/nginx/conf.d/phppgadmin.inc*;
include     /etc/nginx/conf.d/webmail.inc*;

include     /home/admin/conf/web/nginx.chetantest.tk.conf*;

}


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

@inboundRaj

Ideally, you don’t want to nest location blocks, and from looking over your configuration, that’s where the issue is stemming from. Each location block should ideally only handle one thing. So if we take your current server block and rewrite it without nesting and break it apart, it looks like:

server {
    listen 139.59.10.214:80;
    servername chetantest.tk www.chetantest.tk;
    
    root /home/admin/web/chetantest.tk/publichtml;
    
    index index.php index.html index.htm;
    
    accesslog /var/log/nginx/domains/chetantest.tk.log combined;
    accesslog /var/log/nginx/domains/chetantest.tk.bytes bytes;
    error_log /var/log/nginx/domains/chetantest.tk.error.log error;

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
        expires     max;
    }

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

    location ~ [^/]\.php(/|$) {
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        if (!-f $document_root$fastcgi_script_name) {
            return  404;
        }

        fastcgi_pass    127.0.0.1:9003;
        fastcgi_index   index.php;
        include         /etc/nginx/fastcgi_params;
    }

    location /error/ {
        alias   /home/admin/web/chetantest.tk/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    location /vstats/ {
        alias   /home/admin/web/chetantest.tk/stats/;
        include /home/admin/web/chetantest.tk/stats/auth.conf*;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     /home/admin/conf/web/nginx.chetantest.tk.conf*;
}