1

I am running a CentOS version 7 Virtual Machine and trying to proxy it to a subsonic server which is running on Windows Server 2012.

When I was using Apache it was working without issues but I am currently trying to do the same using Nginx but I keep getting 502 bad gateway.

I can't seem to figure what is causing this issue.

My nginx.conf:

server {
    listen       80;
    server_name  *.example.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

server {
    listen  80;
    server_name music.exmaple.com;

    location / {
        proxy_pass http://192.168.1.67:6060/;
        proxy_redirect / http://192.168.1.67:6060/;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   90;
        proxy_send_timeout      90;
        proxy_read_timeout      90;
        proxy_buffers           32 4k;
    }
}

On Apache:

<VirtualHost *:80>
    ServerName music.example.com
    ServerAlias www.music.example.com
    RewriteEngine on
    RewriteRule ^music/(.*)$ http://192.168.1.67:6060/ [P]
    ProxyPass / http://192.168.1.67:6060/
    ProxyPassReverse / http://192.168.1.67:6060/
</VirtualHost>

Telnet to 192.168.1.67:6060

Trying 192.168.1.67...
Connected to 192.168.1.67.
Escape character is '^]'.
dir
HTTP/1.1 400 Bad Request
Connection: close
Server: Jetty(8.y.z-SNAPSHOT)

Error: 400Connection closed by foreign host.

Error log:

2014/10/23 16:51:21 [crit] 11191#0: *1 connect() to 192.168.1.67:6060 failed (13: Permission denied) while connecting to upstream, client: 192.168.1.1, server: music.example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://192.168.1.67:6060/favicon.ico", host: "music.example.com"

What am I doing wrong and how can I fix it?

7
  • Is the new server able to access the 192.168.1.67:6060 address ?
    – umeli
    Oct 23, 2014 at 9:16
  • What does your error log say ? It seems connection attempt to 192.168.1.67:6060 ends up with a RESET packet being received, so either a firewall is rejecting the connection or 192.168.1.67 doesnrt have a service listening on port 6060. What's telnet 192.168.1.67 6060 output ? Oct 23, 2014 at 9:20
  • I am able to access 192.168.1.67 through the browser with no issues if that's what you mean. I have updated the telnet output on the question. Thanks for the help!
    – Hong Yi
    Oct 23, 2014 at 9:35
  • 1
    Isn't that a selinux restriction?
    – Glueon
    Oct 23, 2014 at 10:45
  • 1
    "Permission denied" + Centos7 = selinux : stackoverflow.com/a/24830777/1164809 Oct 23, 2014 at 11:56

1 Answer 1

4

By default SELinux prevents the web server from making outbound connections to foreign hosts.

You can change this and allow outgoing connections by setting the httpd_can_network_connect boolean.

setsebool -P httpd_can_network_connect 1
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.