0

我在我的树莓上通过 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://raspberry-ip-address:3000 时,我从 gogs 获得安装页面 -> 所以 Gogs 运行良好。

当我继续 http://raspberry-ip-address/gogs 时,我收到了 404 Not found 错误。但是来自 Gogs 的日志以某种方式“反应”,因为我得到:

[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 没有正确重定向请求。任何想法 ?

谢谢 ;)

4

1 回答 1

1

对我来说,以下配置有效:

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

但以下(您发布的内容)会产生您提到的错误:

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

注意/url 的 and 和 and 。

HTTP 重定向 (30x) 并不能解决问题,因为它将重定向到localhost的不是树莓派而是执行请求的计算机。

完成 nginx 配置/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;
        }
    }   
}
于 2016-08-25T06:57:56.937 回答