nginx.conf - nginx配置文件模板

前往http://www.itdecent.cn/p/fbb967b0670a直接復制代碼


#4核8g機器的nginx代理配置

#vim /usr/local/nginx/conf/nginx.conf

user? nginx;

#沒有出現(xiàn)io性能問題,采用默認的1即可;非要設(shè)置,必須要和CPU的內(nèi)核數(shù)8匹配

#worker_processes? 1;

#worker_rlimit_nofile 102400;

error_log? /data0/log/nginx/error.log? notice;

pid? ? ? ? /data0/log/nginx/nginx.pid;

#配置影響nginx服務器或與用戶的網(wǎng)絡(luò)連接

events {

? ? use epoll;

? ? worker_connections? 65535;

}

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"';

? ? access_log logs/access.log main;

? ? #client_max_body_size 50m;

? ? #client_body_buffer_size 256k;

? ? #client_header_timeout 120s;

? ? #client_body_timeout 120s;

? ? #send_timeout 1m;

? ? sendfile on;

? ? #tcp_nopush on;

? ? #keepalive_timeout 0;

? ? keepalive_timeout 65;

? ? #gZip配置

? ? #gzip on;

? ? #gzip_http_version 1.1;

? ? #gzip_comp_level 5;

? ? #gzip_min_length 1000;

? ? #gzip_types gzip_types text/csv text/xml text/css text/plain text/javascript application/javascript application/x-javascript application/json application/xml;

? ? #負載均衡服務器列表

? ? upstream data-server {

? ? ? ? server 127.0.0.1:8080;

? ? }

? ? upstream static-web-server {

? ? ? ? server 127.0.0.1:8888;

? ? }

? ? server {

? ? ? ? listen 666;

? ? ? ? server_name localhost;

? ? ? ? #charset koi8-r;

? ? ? ? #access_log logs/host.access.log main;

? ? ? ? # 在Server級別配置反向代理的參數(shù)

? ? ? ? proxy_redirect off ;

? ? ? ? proxy_set_header Host $host;

? ? ? ? proxy_set_header X-Real-IP $remote_addr;

? ? ? ? proxy_set_header REMOTE-HOST $remote_addr;

? ? ? ? proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

? ? ? ? # 第一個必選規(guī)則

? ? ? ? # 直接匹配網(wǎng)站根,起始頁碼跳轉(zhuǎn)到index.html,通過域名訪問網(wǎng)站首頁比較頻繁,使用這個會加速處理

? ? ? ? # 這里是一個靜態(tài)首頁,也可以直接轉(zhuǎn)發(fā)給后端應用服務器

? ? ? ? location = / {

? ? ? ? ? ? rewrite /index.html last;

? ? ? ? ? ? #proxy_pass http://static-web-server/index;

? ? ? ? }

? ? ? ? # 第二個必選規(guī)則是處理靜態(tài)文件請求,這是nginx作為http服務器的強項

? ? ? ? # 有兩種配置模式,目錄匹配或后綴匹配,任選其一或搭配使用

? ? ? ? location ^~ /static/ {

? ? ? ? ? ? #proxy_set_header Host $host:8888; # 根據(jù)需要

? ? ? ? ? ? #proxy_pass http://static-web-server;

? ? ? ? ? ? root /root/static/;

? ? ? ? }

? ? ? ? #location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ {

? ? ? ? #? ? root /root/res/;

? ? ? ? #}

? ? ? ? # 第三個必選規(guī)則

? ? ? ? # 默認反向代理到通用規(guī)則

? ? ? ? location / {

? ? ? ? ? ? # proxy_set_header Host $host:8888; # 根據(jù)需要

? ? ? ? ? ? proxy_pass http://static-web-server;

? ? ? ? }

? ? ? ? # 特殊頁面 1

? ? ? ? location ~* (login|logout).html$ {

? ? ? ? ? ? # proxy_set_header Host $host:666; # 根據(jù)需要

? ? ? ? ? ? proxy_pass http://data-server;

? ? ? ? }

? ? ? ? # 特殊頁面 2

? ? ? ? location ~* openid {

? ? ? ? ? ? # proxy_set_header Host $host:666; # 根據(jù)需要

? ? ? ? ? ? proxy_pass http://data-server;

? ? ? ? }

? ? ? ? # 通用數(shù)據(jù)接口以do或者json結(jié)尾的,反向代理到數(shù)據(jù)服務器

? ? ? ? location ~* .(do|json)$ {

? ? ? ? ? ? # proxy_set_header Host $host:666; # 根據(jù)需要

? ? ? ? ? ? proxy_pass http://data-server;

? ? ? ? }

? ? ? ? # 數(shù)據(jù)接口服務器

? ? ? ? location ~* (login|logout)$ {

? ? ? ? ? ? #proxy_set_header Host $host:666; # 根據(jù)需要

? ? ? ? ? ? proxy_pass http://data-server;

? ? ? ? }

? ? }

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容