2016-08-24 124 views
0

我正在運行一個通過Nginx在我的樹莓上設置Gogs的問題。[Nginx] [Gogs]通過nginx提供服務gogs

我只是想能夠將http://raspberry-ip-address:3000重定向到http://raspberry-ip-address/gogs

下面我nginx的虛擬主機的conf:

server { 
    listen 80; 
    server_name localhost; 

    location /gogs/ { 
     proxy_pass http://localhost:3000; 
    } 
} 

當我走在http://覆盆子IP地址:3000,我從視護目鏡得到安裝頁面 - >所以視護目鏡是捉迷藏很好。

當我在http:// raspberry-ip-address/gogs上找到404找不到的錯誤。然而,從視護目鏡日誌被莫名其妙地「反應」,因爲我得到:

[Macaron] 2016-08-24 14:40:30: Started GET /gogs/ for 127.0.0.1 
[Macaron] 2016-08-24 14:40:30: Completed /gogs/ 302 Found in 1.795306ms 
2016/08/24 14:40:30 [D] Session ID: 8e0bbb6ab5478dde 
2016/08/24 14:40:30 [D] CSRF Token: YfL58XxZUDgwim9qBCosC7EXIGM6MTQ3MTk4MDMxMzMxMTQ3MjgzOQ== 

對於這裏的更多信息是我的nginx/error.log中:

request: "GET /localhost HTTP/1.1", host: "192.168.1.15" 
2016/08/24 14:40:30 [error] 3191#0: *4 open() "/usr/share/nginx/html/install" failed (2: No such file or directory), client: 192.168.1.12, server: localhost, request: "GET /install HTTP/1.1", host: "192.168.1.15" 

在我看來,那Nginx的不正確重定向請求。任何想法 ?

感謝;)

+0

確實[此帖](https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite)幫你嗎? – syntonym

+0

不是,我試着從這篇文章的每一個答案。 如果我的nginx conf如下所示,設置正在工作: server { listen 80; server_name localhost; location/{ proxy_pass http:// localhost:3000; } } – Guillaume

+0

那麼重寫不會重寫URL?或者重寫發生,但不知何故gog仍然會得到'/ gogs /'?即使你把它放在'/ git /'之類的其他地方,它是否會得到'/ gogs /'? – syntonym

回答

1

對我來說,下面的配置工作:

location /gogs/ { 
    proxy_pass http://localhost:3000/; 
} 

但以下(你貼什麼)產生你所說的錯誤:

location /gogs/ { 
    proxy_pass http://localhost:3000; 
} 

注意/和和網址。

HTTP重定向(30X)不解決該問題,因爲它會重定向到localhost這不是樹莓PI但也不請求的計算機。

完整的nginx的conf在/etc/nginx/nginx.conf

user nginx; 
worker_processes 1; 

events { 
    worker_connections 1024; 
} 


http { 
    include  mime.types; 
    default_type application/octet-stream; 

    sendfile  on; 

    keepalive_timeout 65; 

    server { 
     listen  80; 
     server_name localhost; 


     location/{ 
      root /usr/share/nginx/html; 
      index index.html index.htm; 
     } 

     location /git/ { 
      proxy_pass http://127.0.0.1:3333/; 
     } 

     error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
      root /usr/share/nginx/html; 
     } 
    } 
} 
+0

你可以發佈我的整個nginx conf文件嗎? – Guillaume

+0

因爲你確實是對的。它將我的請求重定向到本地計算機(而不是Pi) – Guillaume

+0

如果它仍然不適合你。我在nginx版本1.10.1-1,也許你有一箇舊版本?你是否配置gog以假設前綴? – syntonym