楼主搭了一个 jackett,想试试这玩意。但是它的端口是 9117,想换成 80 端口。所以,需要 nginx 的反向代理。
参考了一下 Jackett 的官方文档( https://github.com/Jackett/Jackett/wiki/Reverse-Proxy )
CentOS7
Jackett 安装在 /home/myname/Jackett 目录下面,端口 9117
e.g. http://myjack.ml:9117 (大家能够看到 Jackett 的登录界面)
nginx 已经安装好了。能够正常启动工作。
e.g. http://myjack.ml (大家能够看到 nginx 的 welcome )
"sudo tail -100 /var/log/nginx/error.log"能够看到下面这句:
2020/03/04 03:49:41 [error] 83094#83094: *2 open() "/usr/share/nginx/html/Jackett" failed (2: No such file or directory), client: xxx.23x.25x.1xx, server: localhost, request: "GET /Jackett HTTP/1.1", host: "myjack.ml"
楼主分析,重定向到 /usr/share/nginx/html/Jackett 这个目录下去了,但楼主改了 指向 jackett 安装目录 root /home/myname/Jackett;
好像没有用。
/etc/nginx/sites-available/jackett.conf
/etc/nginx/sites-enabled/jackett.conf -> ln 到上面这个文件
nginx, /etc/nginx/nginx.conf 里面,我添加了这一句:
include /etc/nginx/sites-enabled/*;
jackett.conf 的内容如下:
server { root /home/myname/Jackett; #不论有没有这一句,都会出现上面 error.log 里面的错误 location /jackett/ { proxy_pass http://127.0.0.1:9117; #http://localhost:9117 错误一样 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $http_host; } }
楼主不会 nginx,只是照葫芦画了一下。有没有高手,帮忙看一眼,这个该如何配置?
万分感谢!
p.s. 我希望能够 http://myjack.ml/jackett 能够正常打开 jackett 的 web UI 当然,最终,我可能会再改改,http://myjack.ml 直接能打开 jackett web UI 更好
Solution:
https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx
运行下面的两个命令
yum install policycoreutils-python
setsebool -P httpd_can_network_connect 1
include /etc/nginx/conf.d/*.conf;
->
#include /etc/nginx/conf.d/*.conf;
然后紧接着添加Jackett 服务的设置
server { server_name localhost; location / { proxy_pass http://localhost:9117; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $http_host; } }
然后,直接打开IP地址或者域名,默认80端口,成功打开Jackett的web UI. 谢谢大家的帮助,给了我很多启发!
![]() | 1 gwy15 2020-03-04 13:07:37 +08:00 你把 /jackett/ 映射到了 9117,但是你的 jackett 服务器的 base url 还是 /,所以 upstream 会返回 404,然后 fallback 到 nginx 的 404。你需要把 jackett 的 base url 改到 /jackett。 |
![]() | 2 yazoox OP @gwy15 thx 不过,我不是很懂你说的 base url 是什么 e.g. http://myjack.ml:9117/UI/Dashboard 你可以看到,Jackett Configuration 里面 Base Path override: /jackett 这是我能够找到的,接近 base url 的地方了。 |
![]() | 3 gzlock 2020-03-04 13:42:30 +08:00 via Android proxy_pass http://127.0.0.1:9117/; 注意结尾要添加斜杠 |
![]() | 4 chotow 2020-03-04 13:48:20 +08:00 进了 nginx 的默认 server 块吧?而 jackett.conf 里没设置域名,所以不管怎么配置都无效。 |
![]() | 5 yazoox OP @chotow 兄弟,能具体说说么?我不是很懂 nginx ``` 2020/03/04 03:49:41 [error] 83094#83094: *2 open() "/usr/share/nginx/html/Jackett" failed (2: No such file or directory), client: xxx.23x.25x.1xx, server: localhost, request: "GET /Jackett HTTP/1.1", host: "myjack.ml" ``` 从 log 看,nginx 应该是找到 jackett 的 server 了吧? @gzlock 刚才按你说的,添加了 / ,但是好像“涛声依旧” |
![]() | 6 blindie 2020-03-04 14:09:17 +08:00 proxy_pass 跟 root 没关系的。讲道理你这简单转发在默认配置 80 那块下面直接写一个 location /jacket {proxy_pass http://127.0.0.1:9117}然后重启一下 nginx 服务就可以了。 |
![]() | 7 blindie 2020-03-04 14:11:30 +08:00 我猜你是没重启 nginx 所以 Nginx 拿到你的 url 就按照默认规则去找了 /usr/share/nginx/html/jackett |
8 hcymk2 2020-03-04 14:13:40 +08:00 /jackett/ ????? |
![]() | 9 NoOne1 2020-03-04 14:17:08 +08:00 配置文件贴出来。。。我给你改 |
![]() | 10 NoOne1 2020-03-04 14:27:09 +08:00 我瞎了。。。简单点说。你在 proxy_pass http://locahost:9117 后面加上 / 就好了。就是 proxy_pass http://locahost:9117/ |
![]() | 11 Niphor 2020-03-04 14:56:01 +08:00 proxy_pass http://127.0.0.1:9117/; 或楼上 |
![]() | 12 yazoox OP @idclight 不行,我试过了。 /etc/nginx/sites-available/jackett.conf ``` server { location /jackett/ { proxy_pass http://127.0.0.1:9117/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $http_host; } } ``` /etc/nginx/nginx.conf ``` user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; } ``` /etc/nginx/conf.d/default.conf ``` server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } } ``` @blindie 兄弟,你的建议我试过了,简单写法也不行...... |
![]() | 15 SakuraKuma 2020-03-04 16:53:05 +08:00 location /jackett/ 改 / |
![]() | 16 dier 2020-03-04 20:00:59 +08:00 via iPhone 添加多个 server server 里面通过多个 server_name (不同域名)来区分 |
![]() | 17 ZField 2020-03-04 20:10:43 +08:00 /etc/nginx/sites-available/jackett.conf /etc/nginx/nginx.conf /etc/nginx/conf.d/default.conf include /etc/nginx/mime.types; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; 是不是路径的问题啊 |
![]() | 18 chotow 2020-03-04 20:11:46 +08:00 @yazoox #5 以下是我个人看法,没真实做过实验,仅供参考。 当前实际命中的是 default.conf 这个配置文件,所以日志显示了 /usr/share/nginx/html/Jackett。 而你的目标是命中 jackett.conf ;为什么没命中呢?因为这两个配置文件都没有设置 server_name。 解决办法,删掉 default.conf,或者在 jackett.conf 中配置 server_name。 此外,proxy_pass 后不要跟斜杠,如果跟了斜杠,需要修改 Jackett 的 Base URL 为「/」(当前是「/jackett 」)。 |
![]() | 19 also24 2020-03-04 20:18:11 +08:00 楼主你是不是忘了配置 server_name ? |
![]() | 20 also24 2020-03-04 20:20:49 +08:00 server { server_name myjack.ml; location / { proxy_pass http://127.0.0.1:9117 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_cache_bypass $http_upgrade; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $http_host; } } |
21 dorothyREN 2020-03-04 20:28:05 +08:00 竟然没有 listen 跟 server_name 这俩参数 |
![]() | 22 wangqianwei 2020-03-04 21:13:04 +08:00 源码地址有文档那么复杂,在默认的配置文件加一个 location 就好 下面的是他的示例: Example config for Nginx: location /jackett { proxy_pass http://127.0.0.1:9117; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $http_host; proxy_redirect off; } |
![]() | 23 wangqianwei 2020-03-04 21:14:28 +08:00 |
![]() | 24 hive 2020-03-04 21:55:58 +08:00 40 分钟过去了,楼主搞好没,啥原因 |
![]() | 25 yanyueio 2020-03-04 22:08:33 +08:00 via Android 逐一排查一下,location 后面的 /,proxypass 就不要 / 了',最后是否配置了 Servername,或者是否命中了 conf 文件。最后两种可能几率笑,我经历过的大概率的是 /,比如在 sub path 下配置 phpmyadmin,当然那里还有静态资源 rewrite 的问题。如果是其他情况,那基本也逃脱不过 nginx 转发服务的范畴吧,。 |
![]() | 26 yazoox OP 搞定! 有兴趣的可以看我前面的附言! |