跳轉nginx官方文檔javascript
#運行用戶.在windows下無效
#user nobody;php
#工做進程 在實際運用時,一般設置成與CPU數量相等
worker_processes 1;css
#全局錯誤日誌
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;html
#PID文件
#pid logs/nginx.pid;前端
#工做模式及鏈接數上限
events {
#epoll是多路複用IO中的一種方式
#僅用於linux2.6以上內核,能夠大大提升nginx的性能
#use epoll
#單個後臺worker process進行的最大併發連接數
worker_connections 1024;
#併發總數是worker_process和worker_connections的乘積
#即max_clients = worker_processes * worker_connections
#在設置了反向代理的狀況下, max_clients = worker_processes * worker_connections/4
#爲何在設置了反向代理要除以4,應該說是一個經驗值(這裏的4不必定正確,須要詳細瞭解反向代理的工做原理才能作最後的肯定)
#worker_connections值的設置跟物理內存有關
#由於併發受IO約束,max_clients的值必須小於系統能夠打開的最大文件數
#而系統能夠打開的最大文件數和內存大小成正比.通常1GB內存的機器上能夠打開的文件數大約是10萬左右
#linux系統查看能夠打開的最大文件數的命令:
#cat /proc/sys/fs/file-max
}java
http {
#設定mime類型 類型由mime.type文件定義
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指令指定nginx是否調用sendfile函數(zero copy方式.只在linux下有效.由於linux在底層支持了sendfile函數)來輸出文件
#對於普通應用,必須設置爲on
#若是用來進行下載等應用磁盤IO重負載應用,可設置爲off以平衡磁盤與網絡I/O處理速度,下降系統的uptime
sendfile on;
#tcp_nopush只有在啓用sendfile狀況下才有效. tcp_nopush與tcp_nodelay是互斥的.二者共同決定Nagle算法是否生效
#tcp_nopush on;
#連接超時時間
#keepalive_timeout 0;
keepalive_timeout 65;
#tcp_nodelay on;node
#容許客戶端請求的最大單文件字節數(在有上傳文件需求時須要注意該配置,總上傳的文件大小超過這個設置值會致使請求直接被終止)
#client_max_body_size 100M;
#客戶端請求使用的緩衝區大小
#client_body_buffer_size 128k;linux
#開啓zip壓縮 gzip壓縮功能能夠節省帶寬但會增長服務器CPU的開銷nginx
#gzip on;
#gzip_http_version 1.0;
#對IE1~6壓縮不起做用
#gzip_disable "MSIE[1-6]";
#設置可壓縮的內容 默認只對text/html進行壓縮
#gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php image/jpeg image/gif image/png;
#nginx作前端代理使用,表示不管後端服務器的headers頭返回什麼信息,都無條件啓用壓縮
#gzip_proxied any;
#最小壓縮的頁面 若是頁面太小,可能會越壓越大,這裏規定大於1K的頁面才啓用壓縮
#gzip_min_length 1024;
#設置系統獲取幾個單位的緩存用於存儲gzip的壓縮結果數據流
#gzip_buffers 4 8K;
#壓縮級別 1~9 從小到大,壓縮比變大但處理速度變慢 通常設置爲3就能夠
#gzip_comp_level 3;
#設定請求緩衝.該參數也可同時在server中設置,
#但在server中設置的值,只有低於nginx主配置中的值纔有意義,
#不然那些有巨大header的請求,依然會受到主配置中large_client_header_buffers的限制
#nginx默認會用client_header_buffer_size這個buffer來讀取header值,
#若是header過大,它就會使用large_client_header_buffers來讀取
#client_header_buffer_size 128k;
#large_client_header_buffers 4 128K;
server {
#偵聽端口
listen 80;
#定義使用localhost訪問
server_name localhost;算法
#charset koi8-r;
#access_log logs/host.access.log main;
#location的語法規則:
#location [=|~|~*|^~] /uri/ {...}
#location @name {...}
#第一種用法的含義:
# =開頭表示精確匹配
# ^~開頭表示URI以某個常規字符串開頭.理解爲匹配url路徑便可
# ~開頭表示區分大小寫的正則匹配
# ~*開頭表示不區分大小寫的正則匹配
# !~和!~*表示區分大小寫及不區分大小寫不匹配的正則
# /開頭通用匹配,任何請求都會匹配到
#多個location配置的匹配順序:
#首先匹配=,其次匹配^~,其次是按文件中順序的正則匹配,最後是/的通用匹配
#第二種用法的含義:
# @用來定義Named Location的.這種Named Location不是用來處理普通的HTTP請求,它是專門用來處理"內部重定向"請求,是服務端的一個轉發行爲
location / {
#定義服務器的默認網站根目錄位置
root html;
#定義首頁索引文件的名稱
index index.html index.htm;
}
#定義錯誤號對應的提示頁面
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#location @的用法
#error_page 404 http://www.baidu.com #直接這樣是不被容許的
#error_page 404 = @fallback #當發現URI對應的頁面不存在,此時就會轉到fallback的location中,進而轉到www.baidu.com頁面
#location @fallback{
# proxy_pass http://www.baidu.com;
#}
#PHP腳本請求所有轉發到Apache中
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
#PHP腳本請求所有轉發到FastCGI處理.使用FastCGI默認配置
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location定義文件類型 \.php表示全部以php做爲文件後綴的文件類型
#location ~ \.php$ {
#root 定義php文件存放路徑(這裏最好設置絕對路徑,不然可能會因爲尋址路徑緣由致使php崩潰)
# root html;
#定義php-cgi的鏈接地址
# fastcgi_pass 127.0.0.1:9000;
#定義php文件類型中的默認索引頁
# fastcgi_index index.php;
#定義頁面請求參數
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#定義fastcgi配置信息將會被保存到nginx/conf/fastcgi_params文件中
# include fastcgi_params;
#}
#禁止訪問.htxxx文件
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
#配置虛擬主機(virtual host)
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
#啓用HTTPS訪問的配置
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}