server { listen 80; //監聽的端口號 server_name localhost; //用域名方式訪問的地址 #charset koi8-r; //編碼 #access_log /var/log/nginx/host.access.log main; //訪問日志文件和名稱 location / { root /usr/share/nginx/html; //靜態文件根目錄 index index.html index.htm; //首頁的索引文件 } #error_page 404 /404.html; //指定錯誤頁面 # redirect server error pages to the static page /50x.html # 把后台錯誤重定向到靜態的50x.html頁面 error_page 500 502 503 504 /50x.html; 當路徑是/50x.html去找/usr/share/nginx/html里面的文件 location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 如果訪問的是.php結尾會把請求轉發給http://127.0.0.1; # 代理PHP腳本到80端口上的apache服務器 值Apache服務器 #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # 把PHP腳本9000端口上監聽的FastCGI服務 執行時PHP服務器 如果訪問的是.php結尾會把請求轉發給127.0.0.1:9000; #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # 不允許訪問.htaccess文件 #location ~ /\.ht { # deny all; 禁止所以人訪問 #} } // 重啟 nginx -s reload systenmctl reload nginx.service // 驗證 nginx -t // 多級代理 http_x_forwarded_for 客戶端代理IP1 代理IP2