2017-11-11 282 views
0

我在nginx代理下的oAuth重定向時遇到問題。我在我的網站上有Google社交登錄按鈕,並且在本地運行良好。當我在線上傳我的項目時,我把它放在nginx代理下,它不再工作。當我點擊登錄時,瀏覽器將我重定向到localhost:3000/auth/google/callback而不是mywebpage.com/auth/google/callback,告訴我該頁面不存在。
我知道這個問題:Nginx proxy with Google OAuth 2.0和我試圖使用他們建議的修復程序,但他們沒有工作,因爲我不運行流星,但與Nginx代理Express上的NodeJS。
他們建議的第二種解決方案是使用proxy_redirect,但它似乎不起作用。我有一個與谷歌oAuth,但每次我點擊它(這是一個瀏覽器重定向,而不是一個彈出)它將我重定向到本地主機:3000這是代理服務器後面的網址。
我嘗試了proxy_redirect的所有可能的配置,但它總是將我重定向到那裏。這是我在nginx中的代理部分:NodeJS oAuth Google Nginx代理

location/{ 
    proxy_pass http://127.0.0.1:3000; 
    proxy_http_version 1.1; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection 'upgrade'; 
    proxy_set_header Host $host; 
    proxy_cache_bypass $http_upgrade; 
    proxy_redirect http://localhost:3000 https://mywebsite.com; 
} 

任何建議嗎?

回答

0

你把這裏面的服務器塊?

server { 
    listen 80; 
    server_name example.com; 
    location/{ 
     proxy_pass http://127.0.0.1:3000; 
     proxy_http_version 1.1; 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection 'upgrade'; 
     proxy_set_header Host $host; 
     proxy_cache_bypass $http_upgrade; 
    } 
} 

嘗試刪除proxy_redirect。我不認爲你可以代理從http到https或https到http。據我所知,協議需要保持不變。