Question
nginx 404 error on all wordpress posts and pages except homepage
Hello;
I followed this tutorial https://www.wphuman.com/setting-up-wordpress-on-lemp-for-beginners/ to set up nginx for my wordpress blog but unfortunately i have been having 404 errors everywhere.
common.conf
port_in_redirect off;
server_tokens off;
autoindex off;
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
client_max_body_size 64m;
client_body_buffer_size 128k;
index index.php index.html index.htm;
log_not_found off;
access_log off;
expires 86400s;
add_header Pragma public;
add_header Cache-Control "max-age=86400, public, must-revalidate, proxy-revalidate";
error_page 403 = 404;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ /(.|wp-config.php|readme.html|licence.txt) {
return 404;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~ /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* ^.+.(css|js)$ {
rewrite ^(.+).(d+).(css|js)$ $1.$3 last;
expires 24h;
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "public";
}
location ~* .(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|ogv|otf|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|t?gz|tif|tiff|ttf|wav|webm|wma|woff|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
expires 24h;
access_log off;
log_not_found off;
add_header Pragma public;
add_header Cache-Control "public";
}
location ~ /. {
deny all;
access_log off;
log_not_found off;
}
location ~* /(?:uploads|files)/.*.php$ {
deny all;
}
here is the one for my domain.conf
server {
# Configure the domain that will run WordPress
listen 80;
listen [::]:80;
server_name www.healthable.org;
error_log /src/www/healthable.org/logs/nginx.error.log;
access_log /src/www/healthable.org/logs/nginx.access.log;
# WordPress needs to be in the webroot of /src/www/healthable.org/public in this case
root /src/www/healthable.org/public;
# pass PHP scripts to Fastcgi listening on Unix socket
# Do not process them if inside WP uploads directory
# If using Multisite or a custom uploads directory,
# please set the */uploads/* directory in the regex below
location ~* (^(?!(?:(?!(php|inc)).)*/uploads/).*?(php)) {
try_files $uri $uri/ /index.php?q=$uri&$args;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
include sites-available/common.conf;
}
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.
×