By heynavigator
Hi,
I’ve been struggling for over a day now to get pretty permalinks to work on WordPress. I’ve tried quite a few solutions from around the web and nothing has been working. This is my conf file:
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name website.com www.website.com;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
include fastcgi_params;
}
location /blog {
root /var/www/html/blog;
index index.php index.html index.htm index.nginx-debian.html;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ /blog/.+\.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Can anyone tell me what I’m doing incorrectly, please? I did not install this with a one-click-install (otherwise it would be using Apache). Wordpress is installed under /blog. Everything works fine except I am unable to publish posts when pretty permalinks are enabled. Thank you!
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!
Accepted Answer
Hello,
What you’ve got there looks correct, you just need to change one slight thing:
location /blog {
root /var/www/html/blog;
index index.php index.html index.htm index.nginx-debian.html;
try_files $uri $uri/ /blog/index.php$is_args$args;
}
Note the blog part before the /index.php
, then do a config test and restart.
Let me know how it goes! Bobby
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.