简体   繁体   English

Wget 和 Nginx 无法获取 localhost 的内容

[英]Wget and Nginx can't get contents of localhost

I can open my Jenkins at http://localhost:8080 on browser, but wget can't do it.我可以在浏览器上的http://localhost:8080上打开我的 Jenkins,但是 wget 不能这样做。

wget http://localhost:8080
--2018-06-12 07:39:56--  http://localhost:8080/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:8080... connected.
HTTP request sent, awaiting response... 403 Forbidden
2018-06-12 07:39:56 ERROR 403: Forbidden.

And curl can do it: curl 可以做到:

curl http://localhost:8080
<html><head><meta http-equiv='refresh' content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body style='background-color:white; color:white;'>


Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

</body></html>

The matter is that my Nginx fails the same like wget , I get Error 502 Bad Gateway on Nginx when trying to route to Jenkins:问题是我的Nginx 与 wget 一样失败,当我尝试路由到 Jenkins 时,我在 Nginx 上收到错误 502 Bad Gateway

This is my Nginx server block for Jenkins:这是我用于 Jenkins 的 Nginx 服务器块:

server {
    listen      80;
    server_name ...;

    location / {
        proxy_pass       http://127.0.0.1:8080;
        proxy_redirect   off;
        proxy_set_header Host $host;
        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;
    }
}

It seems the page you are hitting is redirecting to other page.您点击的页面似乎正在重定向到其他页面。 Please check after commenting out proxy redirect and reloading nginx.请在注释掉代理重定向并重新加载 nginx 后检查。

#proxy_redirect  off

Found the problem, my Nginx config file is totally correct, Jenkins server working fine, but it is because of SELinux which makes Nginx fail to pass request to Jenkins.发现问题,我的 Nginx 配置文件完全正确,Jenkins 服务器工作正常,但这是因为 SELinux 导致 Nginx 无法将请求传递给 Jenkins。

How to disable SELinux :如何禁用 SELinux

  • sudo nano /etc/selinux/config须藤纳米 /etc/selinux/config
  • Set the line 'SELINUX=' to: "SELINUX=disabled"将“SELINUX=”行设置为:“SELINUX=disabled”
  • sudo reboot须藤重启

Having the exact same configuration and error and investigating this issue for 6+ hours this did it to me:拥有完全相同的配置和错误并调查了这个问题 6 个多小时,对我来说是这样的:

在此处输入图片说明

I needed to check Jenkins > Manage Jenkins > Configure Global Security > Authorization > Allow anonymous read access我需要检查 Jenkins > 管理 Jenkins > 配置全局安全性 > 授权 > 允许匿名读取访问

Update: I just realized that opens entire Jenkins Software for public reading.更新:我刚刚意识到这会打开整个 Jenkins 软件以供公众阅读。 Not ideal.不理想。 I'll need to find a proper solution.我需要找到一个合适的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM