nginx參數(shù)的詳細(xì)介紹
nginx參數(shù)的詳細(xì)介紹
最近公司的項(xiàng)目中涉及到舊老項(xiàng)目遷移,需要在nginx上做些配置,所以簡(jiǎn)單學(xué)習(xí)了下,好記性不如爛筆頭,也許可以幫助到大家,
#開(kāi)啟進(jìn)程數(shù) <=CPU數(shù)
worker_processes 1;
#錯(cuò)誤日志保存位置
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#進(jìn)程號(hào)保存文件
#pid logs/nginx.pid;
#等待事件
events {
#每個(gè)進(jìn)程最大連接數(shù)(最大連接=連接數(shù)x進(jìn)程數(shù))
worker_connections 1024;
}
http {
#文件擴(kuò)展名與文件類型映射表
include mime.types;
#默認(rèn)文件類型
default_type application/octet-stream;
#日志文件輸出格式 這個(gè)位置相于全局設(shè)置
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#請(qǐng)求日志保存位置
#access_log logs/access.log main;
#打開(kāi)發(fā)送文件
sendfile on;
#tcp_nopush on;
#連接超時(shí)時(shí)間
#keepalive_timeout 0;
keepalive_timeout 65;
#打開(kāi)gzip壓縮
#gzip on;
#設(shè)定請(qǐng)求緩沖
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
#設(shè)定負(fù)載均衡的服務(wù)器列表
upstream tomcat-servers {
#weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大
#max_fails 當(dāng)有#max_fails個(gè)請(qǐng)求失敗,就表示后端的服務(wù)器不可用,默認(rèn)為1,將其設(shè)置為0可以關(guān)閉檢查
#fail_timeout 在以后的#fail_timeout時(shí)間內(nèi)nginx不會(huì)再把請(qǐng)求發(fā)往已檢查出標(biāo)記為不可用的服務(wù)器
#這里指定多個(gè)源服務(wù)器,ip:端口,80端口的話可寫(xiě)可不寫(xiě)
server 127.0.0.1:8080 weight=5 max_fails=2 fail_timeout=600s;
#server 127.0.0.2:8080 weight=3 max_fails=2 fail_timeout=600s;
}
#第一個(gè)虛擬主機(jī)
server {
#監(jiān)聽(tīng)I(yíng)P端口
listen 80;
#主機(jī)名
server_name localhost;
#設(shè)置字符集
#charset koi8-r;
#本虛擬server的訪問(wèn)日志 相當(dāng)于局部變量
#access_log logs/host.access.log main;
#對(duì)本server"/"啟用負(fù)載均衡
location / {
#root /root; #定義服務(wù)器的默認(rèn)網(wǎng)站根目錄位置
#index index.php index.html index.htm; #定義首頁(yè)索引文件的名稱
proxy_pass http://tomcat-servers; #請(qǐng)求轉(zhuǎn)向tomcat-servers定義的服務(wù)器列表
#以下是一些反向代理的配置可刪除.
# proxy_redirect off;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# client_max_body_size 10m; #允許客戶端請(qǐng)求的最大單文件字節(jié)數(shù)
# client_body_buffer_size 128k; #緩沖區(qū)代理緩沖用戶端請(qǐng)求的最大字節(jié)數(shù),
# proxy_connect_timeout 90; #nginx跟后端服務(wù)器連接超時(shí)時(shí)間(代理連接超時(shí))
# proxy_send_timeout 90; #后端服務(wù)器數(shù)據(jù)回傳時(shí)間(代理發(fā)送超時(shí))
# proxy_read_timeout 90; #連接成功后,后端服務(wù)器響應(yīng)時(shí)間(代理接收超時(shí))
# proxy_buffer_size 4k; #設(shè)置代理服務(wù)器(nginx)保存用戶頭信息的緩沖區(qū)大小
# proxy_buffers 4 32k; #proxy_buffers緩沖區(qū),網(wǎng)頁(yè)平均在32k以下的話,這樣設(shè)置
# proxy_busy_buffers_size 64k; #高負(fù)荷下緩沖大?。╬roxy_buffers*2)
# proxy_temp_file_write_size 64k; #設(shè)定緩存文件夾大小,大于這個(gè)值,將從upstream服務(wù)器傳
}
location /upload {
alias e:/upload;
}
#設(shè)定查看Nginx狀態(tài)的地址
location /NginxStatus {
stub_status on;
access_log off;
#allow 192.168.0.3;
#deny all;
#auth_basic "NginxStatus";
#auth_basic_user_file conf/htpasswd;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
# 定義錯(cuò)誤提示頁(yè)面
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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#多監(jiān)聽(tīng)
# listen 8000;
#主機(jī)名
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
#WEB文件路徑
# root html;
#默認(rèn)首頁(yè)
# index index.html index.htm;
# }
#}
# HTTPS server HTTPS SSL加密服務(wù)器
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
Nginx+Tomcat負(fù)載均衡及動(dòng)靜分離群集的實(shí)現(xiàn)
本文主要介紹了Nginx+Tomcat負(fù)載均衡及動(dòng)靜分離群集的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
配置Nginx以實(shí)現(xiàn)自動(dòng)重啟的方法
要實(shí)現(xiàn)Nginx的自動(dòng)重啟,我們通常會(huì)借助一個(gè)叫做systemd的工具,systemd是Linux系統(tǒng)中的一個(gè)服務(wù)管理器,它可以幫助我們管理系統(tǒng)的各種服務(wù),包括Nginx2025-02-02
nginx提示:500 Internal Server Error錯(cuò)誤解決辦法
這篇文章主要介紹了 nginx提示:500 Internal Server Error錯(cuò)誤解決辦法的相關(guān)資料,這里提供了解決該問(wèn)題的詳細(xì)步驟,希望能幫助到大家,需要的朋友可以參考下2017-08-08
nginx 反向代理之 proxy_pass的實(shí)現(xiàn)
這篇文章主要介紹了nginx 反向代理之 proxy_pass的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
Nginx內(nèi)容緩存以及常見(jiàn)參數(shù)配置詳析
這篇文章主要給大家介紹了關(guān)于Nginx內(nèi)容緩存以及常見(jiàn)參數(shù)配置的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Nginx具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
nginx設(shè)置X-Frame-Options的字段選擇
本文主要介紹了X-Frame-Options選項(xiàng)的三個(gè)值,包含DENY、SAMEORIGIN和ALLOW-FROM uri,具有一定的參考價(jià)值,感興趣的可以了解一下2024-12-12

