2015-10-06 103 views
0

我使用nginx的服務器和Tomcat的,經過我公司採用以下配置Nginx的是重定向到本地主機:8080 USERLOGIN網站

server { 
    listen   80; 
    root   /opt/tomcat/webapps/ROOT; 
    server_name ssss.com; 
    server_name_in_redirect off; 
    access_log /var/log/nginx/sss/site_access.log; 
    error_log /var/log/nginx/sss/site_error.log debug; 

    location/{ 
     proxy_set_header X-Forwarded-Host $host; 
     proxy_set_header X-Forwarded-Server $host; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_cookie_path ~*^/.* /; 
     proxy_pass http://localhost:8080; 
    } 
} 

我的問題是AFTR用戶(給用戶名和密碼)登錄過程我的網址正在播放localhost:8080/Home。

這裏首頁是正確的,但insted localhost:8080應該是我的網站名稱。

如何解決這個問題。

+2

嘗試'proxy_set_header主機$主機;' –

+0

我應該刪除'proxy_set_header X-Forwarded-Host $ host;' – xrcwrn

+0

@AlexeyTen感謝這很完美 – xrcwrn

回答

4

我假設你的web應用程序在localhost:8080上的tomcat上運行。所以你要找的是在運行的tomcat實例之前使用nginx作爲代理。我在這裏的linux開發盒上進行了一個絕對最小配置的小測試。您可以使用以下配置nginx的:

server { 

    listen 80; 

    location/{ 

    proxy_set_header  Host $host; 
    proxy_set_header  X-Real-IP $remote_addr; 
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header  X-Forwarded-Proto $scheme; 

    # Fix the "It appears that your reverse proxy set up is broken" error. 
    proxy_pass   http://127.0.0.1:8080; 
    proxy_read_timeout 90; 

    } 
} 

請注意,這不是在生產中使用!

請考慮例如nginx webpage關於如何保護你的nginx配置/代理設置。

+1

proxy_set_header Host $ host;解決了我的問題 – xrcwrn

+0

你介意接受答案,如果它解決了你的問題? – MWiesner

相關問題