2017-11-25 214 views
0

我有一個反應網站,我在一個運行Nginx的Docker容器內運行,我在端口3000上運行。然後在主機上有一個Nginx實例,它我有一個反向代理指向127.0.0.1:3000反應路由器和nginx給予意外的令牌<

一切工作正常,除了我有一個Twitter身份驗證調用,它使用回調。當url指向mysite.com/authenticated時,這是要求Nginx找到當然會崩潰的路徑。

我已經走遍了互聯網,並發現有很多帖子說明我應該有這在我的nginx的默認文件:

location/{ 
     proxy_pass 127.0.0.1:3000; 
     try_files $uri $uri/ /index.html; 
    } 

當我再瀏覽到我的網站,即使是根,我在得到unexpected token <控制檯錯誤。

什麼可能導致此問題?

回答

0

假設你打電話給外部的twitter api http://twitter/auth.com/twitter/authentication進行驗證。 而在你的反應行動文件中,你已經給了url作爲/twitter/authentication來呼叫。對於這種情況下面的配置。

server { 

location/{ 
     proxy_pass http://127.0.0.1:3000; 
    } 
location /twitter/authentication { 
     proxy_pass http://twitter/auth.com; 
     } 
} 

您必須在nginx config中編寫服務器內的每個位置配置。 在此配置中進行任何修改後,您已重新啓動nginx。

0

對我來說是鏈接app.js

<script src="/app/bundle.js"></script> 

當我試圖在

http://localhost:8080/serv9090 

達到我的應用程序在瀏覽器試圖找到/app/bundle.js通過

http://localhost:8080/app/bundle.js 

在localhost上找不到的是:8080(nginx) 對於第一次嘗試,我更改了

<script src="/app/bundle.js"></script> 

<script src="http://localhost:8080/serv9090/app/bundle.js"></script> 

這工作得很好。 希望這有助於。