This guide needs root access. Root is the all-powerful admin account on a VPS or dedicated server. If you are on shared hosting, you cannot do this. Ask Hostvento support instead.
What are Nginx and permalinks?
Nginx (say "engine-x") is a web server program. It receives requests from visitors and sends back your pages. A permalink is the permanent address of a post. A pretty permalink looks like example.com/my-first-post/. An ugly one looks like example.com/?p=123.
Apache reads a file called .htaccess for pretty links. Nginx does not read that file. So you must tell Nginx yourself. If you do not, posts show "404 Not Found".
Warning: a mistake in an Nginx file can take every site on the server offline. Copy the file before you edit it.
Steps: fix permalinks
- Connect to your server with SSH. SSH is a safe way to type commands on a server.
- Find your site's config file. It is often in
/etc/nginx/conf.d/or/etc/nginx/sites-available/. - Make a copy:
This saves the original under a new name.cp /etc/nginx/conf.d/example.conf /etc/nginx/conf.d/example.conf.bak - Open the file in an editor:
nano /etc/nginx/conf.d/example.conf - Inside the
serverblock, find or add alocation /block, and make it say:
This tells Nginx: try the real file first, then a folder, then hand the request to WordPress.location / { try_files $uri $uri/ /index.php?$args; } - Save the file. In nano, press Ctrl + O, Enter, then Ctrl + X.
- Test the config:
This checks your file for mistakes without applying it. It must say "syntax is ok".nginx -t - Reload Nginx:
This applies the change without cutting off visitors.systemctl reload nginx - In WordPress, go to Settings, then Permalinks. Choose Post name and click Save Changes.
Steps: reach your statistics
Statistics tools such as AWStats make reports from your server logs. If your report folder gives a 404 under WordPress, add a separate location so WordPress does not take over that path. Use your real folder path.
- Open the same config file.
- Above the main
location /block, add:
This serves the folderlocation /stats/ { alias /var/www/stats/; index index.html; }/var/www/stats/at the address/stats/. Use the folder where your tool saves its reports. - Run
nginx -tagain. Then runsystemctl reload nginx. - Visit
yourdomain.com/stats/.
auth_basic setting.Quick recap
- Nginx ignores
.htaccess, so you addtry_filesyourself. - Back up the config, edit, run
nginx -t, then reload. - Save permalinks again in WordPress.
- Give your stats folder its own
locationblock.