简体   繁体   中英

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.

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 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:

This is my Nginx server block for Jenkins:

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.

#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.

How to disable SELinux :

  • sudo nano /etc/selinux/config
  • Set the line 'SELINUX=' to: "SELINUX=disabled"
  • sudo reboot

Having the exact same configuration and error and investigating this issue for 6+ hours this did it to me:

在此处输入图片说明

I needed to check Jenkins > Manage Jenkins > Configure Global Security > Authorization > Allow anonymous read access

Update: I just realized that opens entire Jenkins Software for public reading. Not ideal. I'll need to find a proper solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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