By inboundRaj
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*;
}
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!
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*;
}
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.