Code:
cat nginx.conf
user www www;
worker_processes auto;
# This default error log path is compiled-in to make sure configuration parsing
# errors are logged somewhere, especially during unattended boot when stderr
# isn't normally logged anywhere. This path will be touched on every nginx
# start regardless of error log location configured here. See
# https://trac.nginx.org/nginx/ticket/147 for more info.
#
#error_log /var/log/nginx/error.log;
#
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost; # Change this to your domain name or IP address
# Default web root
root /usr/local/www/nginx; # Or your desired web root, e.g., /usr/local/www/mywebsite.com
# Add index.php to the index directive so Nginx serves it automatically
index index.html index.htm index.php;
# Location block for static files (optional, but good practice)
location / {
try_files $uri $uri/ =404;
}
# Pass PHP scripts to PHP-FPM via TCP
location ~ \.php$ {
alias /usr/local/www/nginx/;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000; # This is the crucial line for TCP socket
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; # Includes common FastCGI parameters
autoindex on; # This enables directory listing
# Optional: Further configure autoindex behavior
autoindex_exact_size off; # Display sizes as KB, MB, GB
autoindex_format html; # (default) or xml, json, jsonp
autoindex_localtime on; # Use local time for file modification dates
}
# Error pages
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
}
}