I have setup my first AWS EC2 account and installed nginx. The root is /usr/share/nginx/html. I have installed WordPress as a sub-folder called cooking under root. the site address is

As long as I have permalink setup as Plain, pages are coming up ok, but when I update permalink structure to use Post Name, I get 404 error. - runs OK - gives 404

Location of WordPress installation (cooking): /usr/share/nginx/html/cooking
Location of .htaccess file: /usr/share/nginx/html/cooking/.htaccess
Content of .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

I am not sure but multisite might be a solution but I don't want to go this far right now, rather I want to keep it simple at the beginning. Basically I will need more sub-folders (different WP installations for different sites) like this under usr/share/nginx/html folder for demonstration purpose.

Please suggest me the right way to achieve this.

I have Permalink setting set to Post Name for the moment, so will give 404 right now, which is OK. But still ends up with 404.

enter image description here

  • htaccess files only work on Apache servers, they'll do nothing for nginx servers. You'll need to modify nginx configs instead – Tom J Nowell Aug 23 '17 at 14:31
  • Yes, after some research I have come to know that nginx has no connection with .htaccess! I am trying to set things up for nginx. @Hasin Hyder is trying to help me out! – Subrata Sarkar Aug 23 '17 at 14:39
  • proptip: steal the nginx configs from VVV, take special note of github.com/Varying-Vagrant-Vagrants/VVV/blob/develop/config/… – Tom J Nowell Aug 23 '17 at 14:42

It's happening because Nginx doesn't interpret rewrite rules like Apache via mod_rewrite. You need to change your nginx vhost config file (nginx site config file, i.e /etc/nginx/sites-enabled/your-site-config.conf file)

Add the following line inside server block

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

if the location / is already present, then remove the existing try_files directive and replace it with the following line

try_files $uri $uri/ /index.php?$args;

Now restart or reload Nginx and your problem will be gone. Here is a good article link regarding this https://www.cyberciti.biz/faq/how-to-configure-nginx-for-wordpress-permalinks/

  • Thank you for your swift reply. the problem is I don't have the folder sites-enabled under /etc/nginx!! What should I do? :( – Subrata Sarkar Aug 23 '17 at 14:16
  • ok what do you have there? – Hasin Hayder Aug 23 '17 at 14:18
  • Under /etc/nginx I have conf.d (folder), fastcgi_params, mime.types, scgi_params, win-utf, default.d (folder), fastcgi_params.default, mime.types.default, scgi_params.default, fastcgi.conf, koi-utf, nginx.conf, uwsgi_params, .conf.default, koi-win, nginx.conf.default, uwsgi_params.default. Under conf.d, two files: default.conf and virtual.conf. There is nothing under default.d folder. – Subrata Sarkar Aug 23 '17 at 14:22
  • It's inside conf.d folder - look for the conf file that has a text line "server_name" which matches to your site address, change only that file – Hasin Hayder Aug 23 '17 at 14:27
  • Adding server name or gives "No input file specified." when I am running I added a screenshot in original post. – Subrata Sarkar Aug 23 '17 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.