#user nobody;php
#開啓進程數 <=CPU數
worker_processes 1;html
#錯誤日誌保存位置
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;nginx
#進程號保存文件
#pid logs/nginx.pid;web
#每一個進程最大鏈接數(最大鏈接=鏈接數x進程數)每一個worker容許同時產生多少個連接,默認1024
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"';tomcat
#請求日誌保存位置
#access_log logs/access.log main;
#打開發送文件
sendfile on;
#tcp_nopush on;服務器
#keepalive_timeout 0;
#鏈接超時時間
keepalive_timeout 65;session
#打開gzip壓縮
#gzip on;
#設定請求緩衝
#client_header_buffer_size 1k;
#large_client_header_buffers 4 4k;
#設定負載均衡的服務器列表
#upstream myproject {
#weigth參數表示權值,權值越高被分配到的概率越大
#max_fails 當有#max_fails個請求失敗,就表示後端的服務器不可用,默認爲1,將其設置爲0能夠關閉檢查
#fail_timeout 在之後的#fail_timeout時間內nginx不會再把請求發往已檢查出標記爲不可用的服務器
#}
#webapp
#upstream myapp {
# server 192.168.1.171:8080 weight=1 max_fails=2 fail_timeout=30s;
# server 192.168.1.172:8080 weight=1 max_fails=2 fail_timeout=30s;
#} app
#配置虛擬主機,基於域名、ip和端口
server {
#監聽端口
listen 80;
#監聽域名
server_name localhost;
#charset koi8-r;
#nginx訪問日誌放在logs/host.access.log下,而且使用main格式(還能夠自定義格式)
#access_log logs/host.access.log main;
#返回的相應文件地址
location / {
#設置客戶端真實ip地址
#proxy_set_header X-real-ip $remote_addr;
#負載均衡反向代理
#proxy_pass http://myapp;
#返回根路徑地址(相對路徑:相對於/usr/local/nginx/)
root html;
#默認訪問文件
index index.html index.htm;
}
#配置反向代理tomcat服務器:攔截.jsp結尾的請求轉向到tomcat
#location ~ \.jsp$ {
# proxy_pass http://192.168.1.171:8080;
#}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 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
#
#location ~ /\.ht {
# deny all;
#}
}
#虛擬主機配置:
server {
listen 1234;
server_name bhz.com;
location / {
#正則表達式匹配uri方式:在/usr/local/nginx/bhz.com下 創建一個test123.html 而後使用正則匹配
#location ~ test {
## 重寫語法:if return (條件 = ~ ~*)
#if ($remote_addr = 192.168.1.200) {
# return 401;
#}
#if ($http_user_agent ~* firefox) {
# rewrite ^.*$ /firefox.html;
# break;
#}
root bhz.com;
index index.html;
}
#location /goods {
# rewrite "goods-(\d{1,5})\.html" /goods-ctrl.html;
# root bhz.com;
# index index.html;
#}
#配置訪問日誌
access_log logs/bhz.com.access.log main;
}
# 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 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;
# }
#}
}