Important: You can use easyengine which automated WordPress-Nginx site management.
There is a famous proverb that goes like this:
A place for everything and everything in its place!
There is no denying to this. So we are devoting a dedicated page for all conventions we have used in wordpress-nginx tutorials series.
This page might feel a little boring to read. But it will help you get a grip on all the conventions used. You will definitely thank me for this when you will end-up breaking something. Because in that panic moment, this page will help you troubleshoot quickly.
Please note that following layout is for Ubuntu 12.04 LTS. Most of them are default locations for respective packages. Sticking with default will save us from some trouble. On non-Ubuntu/Debian OS, some locations may vary.
/etc/nginx/– all nginx related configuration will be in this folder
/etc/nginx/nginx.conf– THE (main) nginx configuration file
/etc/nginx/sites-available/– nginx configuration for different sites will be available here
/etc/nginx/sites-enables/– symlinks to nginx configuration files which are “active”
/var/log/nginx/– default log directory for nginx. We will use this for logs of all sites we will create.
/var/log/nginx/example.com.access.log– access log file for example.com
/var/log/nginx/example.com.error.log– error log file for example.com
/etc/logrotate.d/nginx– this file control log-rotation policy for nginx related log files
/etc/php5/– all php related configuration will be in this folder
/etc/php5/fpm/php.ini– THE (main) php configuration file
/etc/php5/fpm/php-fpm.conf– FPM related settings
/etc/php5/fpm/conf.d/www.conf– “www” i.e. default pool related settings
Note: You may not find following files by default. They were added in by us.
/var/log/php5-fpm/– php related to logs. you should check this if you feel your site is slow or broken
/var/log/php5-fpm/slow.log– this file will help you find slow php scripts
/var/log/php5-fpm/php.log– this file will help you find slow php scripts
/etc/logrotate.d/php5-fpm– this file control how long php logs will be maintained
MySQL – Configuration & logs
/etc/mysql/my.cnf– this is mysql configuration file (not folder)
/var/log/mysql/mysql.log– mysql general/error logs
/var/log/mysql/mysql-slow.log– this file will help you find slow mysql queries
/etc/logrotate.d/mysql-server– this file control how long php logs will be maintained
Following is the convention we will be using for WordPress as well as non-WordPress sites.
/var/www– all your websites will be here
/var/www/example.com– everything related to example.com will be inside this folder
/var/www/example.com/htdocs– this is web-root for example.com. Its like DocumentRoot in Aapche. You will put WordPress will here.
/var/www/example.com/logs– contains logs for example.com only.
/var/www/example.com/logs/access.log– contains access.logs for example.com only. If you want to use a tool like AWStat then this is the server-log file you will need. This is a symbolic link to
/var/www/example.com/logs/error.log– contains error.logs for example.com only. This will help you in debugging. It captures some PHP related error as well. This is a symbolic link to
/var/www/example.com/wp-content– in case you want to keep wp-content outside web-accessible folder. I will NOT cover this in this tutorial. Consider this is an exercise for yourself! 😉
Few notes about the above website-structure:
- Following structure does not take into account shared-hosting scenarios where generally all sites for a users are located under his home directory. Something like /home/bill/www or /home/bill/public_html
- Subdomains are treated like domains. They reside directly under /var/www with their own htdocs and logs folder. e.g. subdomain.example.com will use directory /var/www/subdomain.example.com
Notes about access.log & error.log files for websites:
You might have noticed that you can check access.log & error.log for a domain by 2 ways – either from logs folder under domain or nginx’s log folder. There are few reasons for this kind of setup:
- Keeping all log files places under /var/log/nginx location make things like logrotation, disk cleanup very easy. Also, things like checking logs for all sites hosted on your nginx server or for all subdomains for a top-level domain will be easy.
- Site-specific log folder can make debugging easy. Also, from security perspective you may want to create a user and give him access to a specific site only. In that case we can access logs for that site (if needed)
Related: You can find the complete list of WordPress-Nginx tutorials here.
Important: You can use easyengine which automates WordPress-Nginx site management.