server {
listen 80;
server_name www.example.com example.com;
location / {
root /home/demo/sites/example.com/public_html;
index index.php index.htm index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /home/demo/sites/example.com/public_html$fastcgi_script_name;
include fastcgi_params;
}
}
Explanation
This Nginx configuration sets up a server block that listens on port 80 for requests to www.example.com and example.com. The root directory for the website is specified as /home/demo/sites/example.com/public_html, where the index files are located. The configuration also includes a location block for handling PHP files using PHP-FPM, which is set to communicate over 127.0.0.1:9000.
Common Issues
If you encounter a 403 Forbidden error, ensure that:
- The Nginx user (
www-data) has the necessary permissions to access the files in the specified root directory. - The directory and files have appropriate permissions set (e.g.,
755for directories and644for files). - The SELinux settings (if enabled) are configured to allow Nginx to access the files.
Permissions Example
To set the correct permissions, you can use the following commands:
chown -R www-data:www-data /home/demo/sites/example.com/public_html
chmod -R 755 /home/demo/sites/example.com/public_html