在此記錄下Nginx服務器nginx.conf的配置文件說明, 部分注釋收集與網絡.
#運行用戶user www-data; #啟動進程,通常設置成和cpu的數量相等worker_processes 1;#全局錯誤日志及PID文件error_log /var/log/nginx/error.log;pid /var/run/nginx.pid;#工作模式及連接數上限events {use epoll; #epoll是多路復用IO(I/O Multiplexing)中的一種方式,但是僅用于linux2.6以上內核,可以大大提高nginx的性能worker_connections 1024;#單個后臺worker process進程的最大并發鏈接數# multi_accept on; }#設定http服務器,利用它的反向代理功能提供負載均衡支持http {#設定mime類型,類型由mime.type文件定義include /etc/nginx/mime.types;default_type application/octet-stream;#設定日志格式access_log /var/log/nginx/access.log;#sendfile 指令指定 nginx 是否調用 sendfile 函數(zero copy 方式)來輸出文件,對于普通應用,#必須設為 on,如果用來進行下載等應用磁盤IO重負載應用,可設置為 off,以平衡磁盤與網絡I/O處理速度,降低系統的uptime.sendfile on;#tcp_nopush on;#連接超時時間#keepalive_timeout 0;keepalive_timeout 65;tcp_nodelay on;#開啟gzip壓縮gzip on;gzip_disable "MSIE [1-6]/.(?!.*SV1)";#設定請求緩沖client_header_buffer_size 1k;large_client_header_buffers 4 4k;include /etc/nginx/conf.d/*.conf;include /etc/nginx/sites-enabled/*;#設定負載均衡的服務器列表upstream mysvr {#weigth參數表示權值,權值越高被分配到的幾率越大#本機上的Squid開啟3128端口server 192.168.8.1:3128 weight=5;server 192.168.8.2:80 weight=1;server 192.168.8.3:80 weight=6;}server {#偵聽80端口listen 80;#定義使用www.xx.com訪問server_name www.xx.com;#設定本虛擬主機的訪問日志access_log logs/www.xx.com.access.log main;#默認請求location / {root /root; #定義服務器的默認網站根目錄位置index index.php index.html index.htm; #定義首頁索引文件的名稱fastcgi_pass www.xx.com;fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include /etc/nginx/fastcgi_params;}# 定義錯誤提示頁面error_page 500 502 503 504 /50x.html; location = /50x.html {root /root;}#靜態文件,nginx自己處理location ~ ^/(images|javascript|js|css|flash|media|static)/ {root /var/www/virtual/htdocs;#過期30天,靜態文件不怎么更新,過期可以設大一點,如果頻繁更新,則可以設置得小一點。expires 30d;}#PHP 腳本請求全部轉發到 FastCGI處理. 使用FastCGI默認配置.location ~ /.php$ {root /root;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /home/www/www$fastcgi_script_name;include fastcgi_params;}#設定查看Nginx狀態的地址location /NginxStatus {stub_status on;access_log on;auth_basic "NginxStatus";auth_basic_user_file conf/htpasswd;}#禁止訪問 .htxxx 文件location ~ //.ht {deny all;}}}以上是一些基本的配置,使用Nginx最大的好處就是負載均衡
新聞熱點
疑難解答