1. 程式人生 > 其它 >nginx反向代理配置(conf檔案中的nginx)

nginx反向代理配置(conf檔案中的nginx)

########### 每個指令必須有分號結束。#################
#user administrator administrators;  #配置使用者或者組,預設為nobody nobody。
#worker_processes 2;  #允許生成的程序數,預設為1
#pid /nginx/pid/nginx.pid;   #指定nginx程序執行檔案存放地址
error_log log/error.log debug;  #制定日誌路徑,級別。這個設定可以放入全域性塊,http塊,server塊,級別以此為:debug|info|notice|warn|error|crit|alert|emerg
events {
    accept_mutex on;   #設定網路連線序列化,防止驚群現象發生,預設為on
    multi_accept on;  #設定一個程序是否同時接受多個網路連線,預設為off
    #use epoll;      #事件驅動模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
    worker_connections  1024;    #最大連線數,預設為512
}
http {
    include       mime.types;   #副檔名與檔案型別對映表
    default_type  application/octet-stream; #預設檔案型別,預設為text/plain
    #access_log off; #取消服務日誌    
    log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; #自定義格式
    access_log log/access.log myFormat;  #combined為日誌格式的預設值
    sendfile on;   #允許sendfile方式傳輸檔案,預設為off,可以在http塊,server塊,location塊。
    sendfile_max_chunk 100k;  #每個程序每次呼叫傳輸數量不能大於設定的值,預設為0,即不設上限。
    keepalive_timeout 65;  #連線超時時間,預設為75s,可以在http,server,location塊。

    upstream mysvr {   
      server 10.10.18.39:8081;
      server 192.168.10.121:3333 backup;  #熱備
    }
    error_page 404 https://www.baidu.com; #錯誤頁
    server {
        keepalive_requests 120; #單連線請求上限次數。
        listen       4545;   #監聽埠
        server_name  10.10.18.39;   #監聽地址       
        location  ~*^.+$ {       #請求的url過濾,正則匹配,~為區分大小寫,~*為不區分大小寫。
           #root path;  #根目錄
           #index vv.txt;  #設定預設頁
           proxy_pass  http://mysvr;  #請求轉向mysvr 定義的伺服器列表
           #deny 10.10.18.39;  #拒絕的ip
           allow 172.18.5.54; #允許的ip           
        } 
    }
}