New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果我想用nginx进行代理,该怎么设置呢? #49

Closed
tchroot opened this Issue Nov 16, 2017 · 16 comments

Comments

Projects
None yet
3 participants
@tchroot

tchroot commented Nov 16, 2017

昨天尝试用nginx代理hitchhiker,发现没代理成功

server {
    listen 80 default_server;
    server_name $hostname;
    access_log  off; 
    location /static/ {
        root /etc/hitchhiker;
        expires max;
    }
    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-for $proxy_add_x_forwarded_for;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        client_max_body_size 1024M;
    }
}

哪位大神能指教下

@brookshi

This comment has been minimized.

Show comment
Hide comment
@brookshi

brookshi Nov 16, 2017

Owner

在/etc/hitchhiker后面加上 /public 试试

Owner

brookshi commented Nov 16, 2017

在/etc/hitchhiker后面加上 /public 试试

@brookshi

This comment has been minimized.

Show comment
Hide comment
@brookshi

brookshi Nov 16, 2017

Owner

可以参考下我这个:

server {
        listen 80;
        server_name www.hitchhiker-api.com;
        access_log  /var/log/nginx/api_access.log;

        location / {
            limit_req zone=perip burst=5;
            proxy_pass  http://api;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
		proxy_http_version 1.1;
		proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
	}

	location /static/ {
        proxy_pass http://api;
        root /my/hitchhiker/public;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public";
	}
}
Owner

brookshi commented Nov 16, 2017

可以参考下我这个:

server {
        listen 80;
        server_name www.hitchhiker-api.com;
        access_log  /var/log/nginx/api_access.log;

        location / {
            limit_req zone=perip burst=5;
            proxy_pass  http://api;
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
		proxy_http_version 1.1;
		proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
	}

	location /static/ {
        proxy_pass http://api;
        root /my/hitchhiker/public;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public";
	}
}

@brookshi brookshi added the Question label Nov 16, 2017

@tchroot

This comment has been minimized.

Show comment
Hide comment
@tchroot

tchroot Nov 16, 2017

用你的试了,好使,不过左上角的logo变了样子,索性不代理了 直接docker-compose的时候用了80端口,不然太麻烦了。

tchroot commented Nov 16, 2017

用你的试了,好使,不过左上角的logo变了样子,索性不代理了 直接docker-compose的时候用了80端口,不然太麻烦了。

@brookshi

This comment has been minimized.

Show comment
Hide comment
@brookshi

brookshi Nov 16, 2017

Owner

logo变样子应该是svg没支持好,没其他服务的话不用代理也行,我是有个邮件服务在一起,所以用个nginx分发下

Owner

brookshi commented Nov 16, 2017

logo变样子应该是svg没支持好,没其他服务的话不用代理也行,我是有个邮件服务在一起,所以用个nginx分发下

@brookshi brookshi closed this Nov 17, 2017

@vmvz

This comment has been minimized.

Show comment
Hide comment
@vmvz

vmvz Mar 9, 2018

@brookshi 要注意的是hitchhiker和nginx对主机的端口不能冲突。 你这个配置文件中 nginx的80 和 http://api 岂不是冲突了?

vmvz commented Mar 9, 2018

@brookshi 要注意的是hitchhiker和nginx对主机的端口不能冲突。 你这个配置文件中 nginx的80 和 http://api 岂不是冲突了?

@brookshi

This comment has been minimized.

Show comment
Hide comment
@brookshi

brookshi Mar 9, 2018

Owner

@vmvz 是指docker里配置的端口,不然就会有两个程序共用一个端口了

Owner

brookshi commented Mar 9, 2018

@vmvz 是指docker里配置的端口,不然就会有两个程序共用一个端口了

@vmvz

This comment has been minimized.

Show comment
Hide comment
@vmvz

vmvz Mar 9, 2018

@brookshi 如果这样配置http://api的话, 如何配置 docker-compose.yml ?

nginx起代理作用,居然可以反代 http://api 我不能理解, 我用Python的时候, 基本上都是 nginx 反代 ' http://api:8080'

vmvz commented Mar 9, 2018

@brookshi 如果这样配置http://api的话, 如何配置 docker-compose.yml ?

nginx起代理作用,居然可以反代 http://api 我不能理解, 我用Python的时候, 基本上都是 nginx 反代 ' http://api:8080'

@brookshi

This comment has been minimized.

Show comment
Hide comment
@brookshi

brookshi Mar 9, 2018

Owner

哦,http://api 其实是个简写来的,实际上是http://localhost:8080

Owner

brookshi commented Mar 9, 2018

哦,http://api 其实是个简写来的,实际上是http://localhost:8080

@vmvz

This comment has been minimized.

Show comment
Hide comment
@vmvz

vmvz Mar 9, 2018

@tchroot 更换域名以后, 还是请求老的api, 有办法处理吗? http://old.domain:8080/api/user/temp

不好弄, 我就重新搞一个.

vmvz commented Mar 9, 2018

@tchroot 更换域名以后, 还是请求老的api, 有办法处理吗? http://old.domain:8080/api/user/temp

不好弄, 我就重新搞一个.

@vmvz

This comment has been minimized.

Show comment
Hide comment
@vmvz

vmvz Mar 9, 2018

@tchroot 我已经用nginx反代了, 每次请求api 还是去localhost
image

vmvz commented Mar 9, 2018

@tchroot 我已经用nginx反代了, 每次请求api 还是去localhost
image

@brookshi

This comment has been minimized.

Show comment
Hide comment
@brookshi

brookshi Mar 9, 2018

Owner

host 需要 改成对外访问的,比如用的域名,docker-compose.yml里的host需要改成域名及端口,而不是localhost

Owner

brookshi commented Mar 9, 2018

host 需要 改成对外访问的,比如用的域名,docker-compose.yml里的host需要改成域名及端口,而不是localhost

@vmvz

This comment has been minimized.

Show comment
Hide comment
@vmvz

vmvz Mar 9, 2018

@brookshi 既然nginx配置分享了,顺便把 www.hitchhiker-api.com 部署的 docker-compose.yml 文件贴出来给我们参考吧

vmvz commented Mar 9, 2018

@brookshi 既然nginx配置分享了,顺便把 www.hitchhiker-api.com 部署的 docker-compose.yml 文件贴出来给我们参考吧

@brookshi

This comment has been minimized.

Show comment
Hide comment
@brookshi

brookshi Mar 9, 2018

Owner

image
如果域名后面不加端口,docker的端口就只能是8080

Owner

brookshi commented Mar 9, 2018

image
如果域名后面不加端口,docker的端口就只能是8080

@vmvz

This comment has been minimized.

Show comment
Hide comment
@vmvz

vmvz Mar 9, 2018

@brookshi 今天折腾得我怀疑自己了.

docker部署
假设外网地址是 1.2.4.8 , 域名 www.a.com

简单说, 我已经和你的配置几乎一样了,除了域名不同,
访问 www.a.com 的时候, 首页正常打开, 但是注册或try without login的时候
控制台看到api还是调用这样的地址 http://1.2.4.8:8080/api/user/temp

最后我放弃了, 我用 http://1.2.4.8:8080/ 这样的方式直接访问了, 反正又不是对外用的.

不过有空再次折腾一下试试.

(PS: nginx debian nodejs 部署我还是比较熟悉的,经验也不少呀)

vmvz commented Mar 9, 2018

@brookshi 今天折腾得我怀疑自己了.

docker部署
假设外网地址是 1.2.4.8 , 域名 www.a.com

简单说, 我已经和你的配置几乎一样了,除了域名不同,
访问 www.a.com 的时候, 首页正常打开, 但是注册或try without login的时候
控制台看到api还是调用这样的地址 http://1.2.4.8:8080/api/user/temp

最后我放弃了, 我用 http://1.2.4.8:8080/ 这样的方式直接访问了, 反正又不是对外用的.

不过有空再次折腾一下试试.

(PS: nginx debian nodejs 部署我还是比较熟悉的,经验也不少呀)

@brookshi

This comment has been minimized.

Show comment
Hide comment
@brookshi

brookshi Mar 9, 2018

Owner

@vmvz 最关键的是HITCHHIKER_APP_HOST一定要是 http://www.a.com/ 因为应用启动后会找到main.js,用这个host替换掉里面的一个地址,也就是浏览器里看到了,你那里没替换掉,所以还是ip

Owner

brookshi commented Mar 9, 2018

@vmvz 最关键的是HITCHHIKER_APP_HOST一定要是 http://www.a.com/ 因为应用启动后会找到main.js,用这个host替换掉里面的一个地址,也就是浏览器里看到了,你那里没替换掉,所以还是ip

@vmvz

This comment has been minimized.

Show comment
Hide comment
@vmvz

vmvz Mar 9, 2018

@brookshi 谢谢你耐心的解答.

我确定 HITCHHIKER_APP_HOST=http://www.a.com/

本地还用隐身模式,防止缓存

这么晚了,早点休息吧... 明天我再来一遍, 全部配置贴出来

vmvz commented Mar 9, 2018

@brookshi 谢谢你耐心的解答.

我确定 HITCHHIKER_APP_HOST=http://www.a.com/

本地还用隐身模式,防止缓存

这么晚了,早点休息吧... 明天我再来一遍, 全部配置贴出来

@vmvz vmvz referenced this issue May 10, 2018

Closed

nginx 配置问题 #175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment