1. 程式人生 > >nginx反向代理,使用request.getServerName()獲取域名錯誤

nginx反向代理,使用request.getServerName()獲取域名錯誤

    # 反向代理服務,繫結域名www.abc.com  
        server {  
    listen       80;  
    server_name  www.abc.com;  
     
    charset utf-8;  
     
    # BBS使用Discuz!   
    # 因反向代理為了提高效能,一部分http頭部資訊不會轉發給後臺的伺服器,  
    # 使用proxy_pass_header 和 proxy_set_header 把有需要的http頭部資訊轉發給後臺伺服器  
    location ^~ /bbs/ {  
       root   html;  
       access_log off;  
       index index.php;  
       # 轉發host的資訊,如果不設定host,在後臺使用request.getServerName()取到的域名不是www.abc.com,而是127.0.0.1  
proxy_set_header Host $host; # 因Discuz! 為了安全,需要獲取客戶端User-Agent來判斷每次POST資料是否跟第一次請求來自同1個瀏覽器, # 如果不轉發User-Agent,Discuz! 提交資料就會報"您的請求來路不正確,無法提交"的錯誤 proxy_pass_header User-Agent; proxy_pass http://127.0.0.1:8081; }