This is a simple example of an nginx config for a WordPress site that is setup on a subdirectory install. This is quite literally the exact configuration of this site since our entire WordPress site is at http://robido.com.
We are, as always, open to any suggestions on how we can make this better, and the following config has some stuff that’s specific to this site. One thing that’s always good to have is fastcgi passing through the local unix: protocol so there’s no network overhead. If you need help doing so, add a comment to this post and I’ll send you some steps on how to do that. The rest is fairly basic.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
server { listen 80; server_name .robido.com; root /www/robido.com/public; client_max_body_size 512M; # Logs access_log /www/robido.com/logs/access.log main; error_log /www/robido.com/logs/error.log; # Default location settings location / { index index.html index.htm index.php; } location /blog { index index.html index.htm index.php; try_files $uri $uri/ /blog/index.php?$args; } # Redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } #error_page 404 /404.html; # Pass the PHP scripts to FastCGI server (locally with unix: param to avoid network overhead) location ~ \.php$ { # Prevent Zero-day exploit try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini fastcgi_pass unix:/var/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # Deny access to .htaccess files, if Apache's document root location ~ /\.ht { deny all; } # Exclude favicon from the logs to avoid bloating when it's not available location /favicon.ico { log_not_found off; access_log off; } } |
If you are looking to setup phpMyAdmin on for your site(s) like http://yoursite.com/sqladmin/ then check out my other tutorial here:
http://robido.com/nginx/configure-an-nginx-virtual-host-with-phpmyadmin-and-php-fpm/
Your config works well, except when I attempt to login to wp-admin none of the pages show up. Login works, and I get the sidebar: plugins, themes, dashboard, etc. However, when I press on any of them, the main page remains blank. Except for Jetpack. That page loads fine for some reason.
Any idea?
Hmm, sounds like an error in a plugin or theme file to me. I’d check your PHP error logs for more info. If the problem isn’t obvious:
Try disabling all the plugins by moving them out of the plugins folder and refreshing the admin. If that fixes it, move your plugins back and enable one at a time. As soon as it breaks, you found the problematic plugin.
Or… activate any of the default themes and see if that fixes it. If these don’t work, paste your error log here.
Yep, disabling the plugins fixed it. Didn’t find out exactly which plugin caused my problems, as I decided to not activate all my original plugins. Site works now though, thanks!
Hi, nice example, but I’ve already tried something like this.
Let me explain my problem, and if you could help it will be AWESOME.
I’m running a WordPress install at this address: http://www.zeek.me
Everything works perfect and smoothy.
I also have, in a subdirectory of the WordPress Root, a folder /he where I run another WordPress Install : http://www.zeek.me/he
My problem is that I can’t work with Postame permalinks because when I set them here is the result:
http://www.zeek.me/he/contact-us/
redirects to
http://www.zeek.me/contact-us/ (the root website)
Hope I explained it well, and you’ll have a solution for my problem.
Hope to read from u soon,
Thanks,
Simon
Hey Simon,
Does the /he/contact-us link on your other subdirectory install have a contact-us permalink that it’s supposed to render? If it does then what I’ll do is setup a site structure like yours later this evening and do some tests on this config. Usually the try_files should catch the first one (the subdirectory site) but I rarely setup a parent site with a child subdirectory site like this so I’ll have to play around with the configs to see how to resolve this for you.
Yes the permalinks are setted correctly and the address too. I just can’t access this url because of some rewrite rule
Hey Simon,
Can you post an example of your nginx vhost config file(s)? I was able to get this to work fine on my server so I want to confirm your configuration.
Hello;
i am trying to install phpmyadmin on one of my blogs as i have 2 on one digital ocean droplet. how do i go about it? and were is the .conf for sqladmin?
Hey kingsley,
I’ll remove the sqladmin.conf from this tutorial so it doesn’t cause other people issues, but if you’re looking to setup the same phpmyadmin config that I have, then check out my other post here for a tutorial on setting it up:
http://robido.com/nginx/configure-an-nginx-virtual-host-with-phpmyadmin-and-php-fpm/
Hey,
Thank you for your help. Your blog post helps me fix an issue on my blog (from Apache to Nginx migration, easy :p)
Have a nice sunday,
Geoffrey