nginx reverse proxy for docker swarm - 502 bad gatewayHow to make nginx reverse proxy let 503 error pages pass through to client?NGINX reverse proxy beind another nginx reverse proxyNginx Reverse Proxy 502 Bad GatewayDocker containers behind reverse proxy - rewrite issues with CMS'sreverse proxy nginx bad gatewaynginx reverse proxy inside docker with proxy_redirect defaultnginx reverse proxy + docker spring war applicationnginx reverse proxy for Docker 1.13 “Swarm Mode” clusterReverse Proxy for Docker Swarm with Dynamic Portsnginx reverse proxy to docker containers is timing out

GFCI Outlet in Bathroom, Lights not working

Unconventional Opposites

If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?

Is it legal in the UK for politicians to lie to the public for political gain?

Applicants clearly not having the skills they advertise

What is a simple, physical situation where complex numbers emerge naturally?

Credit card offering 0.5 miles for every cent rounded up. Too good to be true?

Explain Ant-Man's "not it" scene from Avengers: Endgame

Comma Code - Ch. 4 Automate the Boring Stuff

Opposite of "Squeaky wheel gets the grease"

Why were the Night's Watch required to be celibate?

Is it possible for people to live in the eye of a permanent hypercane?

Word for a small burst of laughter that can't be held back

How can I grammatically understand "Wir über uns"?

Did thousands of women die every year due to illegal abortions before Roe v. Wade?

How can I add depth to my story or how do I determine if my story already has depth?

Do adult Russians normally hand-write Cyrillic as cursive or as block letters?

PhD student with mental health issues and bad performance

How can Iron Man's suit withstand this?

Why was it possible to cause an Apple //e to shut down with SHIFT and paddle button 2?

Was the 1959 Tibetan Uprising really an uprising?

Rotated Position of Integers

Why is Colorado so different politically from nearby states?

Creating Fictional Slavic Place Names



nginx reverse proxy for docker swarm - 502 bad gateway


How to make nginx reverse proxy let 503 error pages pass through to client?NGINX reverse proxy beind another nginx reverse proxyNginx Reverse Proxy 502 Bad GatewayDocker containers behind reverse proxy - rewrite issues with CMS'sreverse proxy nginx bad gatewaynginx reverse proxy inside docker with proxy_redirect defaultnginx reverse proxy + docker spring war applicationnginx reverse proxy for Docker 1.13 “Swarm Mode” clusterReverse Proxy for Docker Swarm with Dynamic Portsnginx reverse proxy to docker containers is timing out






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am running a docker swarm on "swarm.example.com". On the server, there's a container running that can be accessed on "swarm.example.com:3000".



On server "example.com" I'm running an nginx reverse proxy with following rules



server 
listen 80;
server_name app.example.com;

location /
proxy_pass http://swarm.example.com:3000;




When I try to access app.example.com im getting 502 Bad Gatway error. Am I missing something ?



All servers are running CentOS 7.6



Thanks!










share|improve this question
























  • Anything in the nginx error log?

    – Gerald Schneider
    May 17 at 19:51






  • 1





    also check the selinux audit.log, selinux might cause problems

    – Gerald Schneider
    May 17 at 19:53











  • Is your proxy also in a container? If they are both in containers, are the connected to the same network? If the proxy is not in a container and on the same network, then have you 'published' the port 3000? Please consider giving us more details about your containers/networks.

    – Zoredache
    May 17 at 21:38












  • @Zoredache no the proxy is on a different physical server

    – Branislav B.
    May 17 at 22:23






  • 2





    Don't disable SELinux, fix the problem instead.

    – Michael Hampton
    May 18 at 1:46

















1















I am running a docker swarm on "swarm.example.com". On the server, there's a container running that can be accessed on "swarm.example.com:3000".



On server "example.com" I'm running an nginx reverse proxy with following rules



server 
listen 80;
server_name app.example.com;

location /
proxy_pass http://swarm.example.com:3000;




When I try to access app.example.com im getting 502 Bad Gatway error. Am I missing something ?



All servers are running CentOS 7.6



Thanks!










share|improve this question
























  • Anything in the nginx error log?

    – Gerald Schneider
    May 17 at 19:51






  • 1





    also check the selinux audit.log, selinux might cause problems

    – Gerald Schneider
    May 17 at 19:53











  • Is your proxy also in a container? If they are both in containers, are the connected to the same network? If the proxy is not in a container and on the same network, then have you 'published' the port 3000? Please consider giving us more details about your containers/networks.

    – Zoredache
    May 17 at 21:38












  • @Zoredache no the proxy is on a different physical server

    – Branislav B.
    May 17 at 22:23






  • 2





    Don't disable SELinux, fix the problem instead.

    – Michael Hampton
    May 18 at 1:46













1












1








1


0






I am running a docker swarm on "swarm.example.com". On the server, there's a container running that can be accessed on "swarm.example.com:3000".



On server "example.com" I'm running an nginx reverse proxy with following rules



server 
listen 80;
server_name app.example.com;

location /
proxy_pass http://swarm.example.com:3000;




When I try to access app.example.com im getting 502 Bad Gatway error. Am I missing something ?



All servers are running CentOS 7.6



Thanks!










share|improve this question
















I am running a docker swarm on "swarm.example.com". On the server, there's a container running that can be accessed on "swarm.example.com:3000".



On server "example.com" I'm running an nginx reverse proxy with following rules



server 
listen 80;
server_name app.example.com;

location /
proxy_pass http://swarm.example.com:3000;




When I try to access app.example.com im getting 502 Bad Gatway error. Am I missing something ?



All servers are running CentOS 7.6



Thanks!







nginx centos reverse-proxy selinux






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 18 at 8:23









Gerald Schneider

7,14732748




7,14732748










asked May 17 at 19:34









Branislav B.Branislav B.

152




152












  • Anything in the nginx error log?

    – Gerald Schneider
    May 17 at 19:51






  • 1





    also check the selinux audit.log, selinux might cause problems

    – Gerald Schneider
    May 17 at 19:53











  • Is your proxy also in a container? If they are both in containers, are the connected to the same network? If the proxy is not in a container and on the same network, then have you 'published' the port 3000? Please consider giving us more details about your containers/networks.

    – Zoredache
    May 17 at 21:38












  • @Zoredache no the proxy is on a different physical server

    – Branislav B.
    May 17 at 22:23






  • 2





    Don't disable SELinux, fix the problem instead.

    – Michael Hampton
    May 18 at 1:46

















  • Anything in the nginx error log?

    – Gerald Schneider
    May 17 at 19:51






  • 1





    also check the selinux audit.log, selinux might cause problems

    – Gerald Schneider
    May 17 at 19:53











  • Is your proxy also in a container? If they are both in containers, are the connected to the same network? If the proxy is not in a container and on the same network, then have you 'published' the port 3000? Please consider giving us more details about your containers/networks.

    – Zoredache
    May 17 at 21:38












  • @Zoredache no the proxy is on a different physical server

    – Branislav B.
    May 17 at 22:23






  • 2





    Don't disable SELinux, fix the problem instead.

    – Michael Hampton
    May 18 at 1:46
















Anything in the nginx error log?

– Gerald Schneider
May 17 at 19:51





Anything in the nginx error log?

– Gerald Schneider
May 17 at 19:51




1




1





also check the selinux audit.log, selinux might cause problems

– Gerald Schneider
May 17 at 19:53





also check the selinux audit.log, selinux might cause problems

– Gerald Schneider
May 17 at 19:53













Is your proxy also in a container? If they are both in containers, are the connected to the same network? If the proxy is not in a container and on the same network, then have you 'published' the port 3000? Please consider giving us more details about your containers/networks.

– Zoredache
May 17 at 21:38






Is your proxy also in a container? If they are both in containers, are the connected to the same network? If the proxy is not in a container and on the same network, then have you 'published' the port 3000? Please consider giving us more details about your containers/networks.

– Zoredache
May 17 at 21:38














@Zoredache no the proxy is on a different physical server

– Branislav B.
May 17 at 22:23





@Zoredache no the proxy is on a different physical server

– Branislav B.
May 17 at 22:23




2




2





Don't disable SELinux, fix the problem instead.

– Michael Hampton
May 18 at 1:46





Don't disable SELinux, fix the problem instead.

– Michael Hampton
May 18 at 1:46










1 Answer
1






active

oldest

votes


















1














Trying to access the backend via the reverse proxy results in a 502 Bad Gateway error:



$ wget -S --spider http://nginxtest.example.com/
Spider mode enabled. Check if remote file exists.
--2019-05-18 10:12:11-- http://nginxtest.example.com/
Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 502 Bad Gateway
Server: nginx/1.12.2
Date: Sat, 18 May 2019 08:12:11 GMT
Content-Type: text/html
Content-Length: 3693
Connection: keep-alive
ETag: "5a9e5ebd-e6d"
Remote file does not exist -- broken link!!!


This is most probably because selinux by default doesn't allow outgoing connections for webservers, because that's usually something they don't do.



You will find entries like this in /var/log/nginx/error.log:




2019/05/18 10:12:11 [crit] 1041#0: *5 connect() to 192.168.15.52:3000 failed (13: Permission denied) while connecting to upstream, client: 146.140.37.47, server: _, request: "HEAD / HTTP/1.1", upstream: "http://192.168.15.52:3000/", host: "nginxtest.example.com"




Additionally, you will find entries like this in /var/log/audit/audit.log:




type=AVC msg=audit(1558167131.910:463): avc: denied name_connect for pid=1041 comm="nginx" dest=3000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ntop_port_t:s0 tclass=tcp_socket permissive=0
type=SYSCALL msg=audit(1558167131.910:463): arch=c000003e syscall=42 success=no exit=-13 a0=8 a1=562671c4eef0 a2=10 a3=7ffcfbc72530 items=0 ppid=1006 pid=1041 auid=4294967295 uid=996 gid=994 euid=996 suid=996 fsuid=996 egid=994 sgid=994 fsgid=994 tty=(none) ses=4294967295 comm="nginx" exe="/usr/sbin/nginx" subj=system_u:system_r:httpd_t:s0 key=(null)




Run the following command to allow nginx to connect to other hosts:



setsebool -P httpd_can_network_connect true


(The parameter -p makes the setting persistent. Otherwise it would be reset after the next reboot.)



And now the proxy works:



$ wget -S --spider http://nginxtest.example.com/
Spider mode enabled. Check if remote file exists.
--2019-05-18 10:15:14-- http://nginxtest.example.com/
Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sat, 18 May 2019 08:15:15 GMT
Content-Type: text/html
Content-Length: 40
Connection: keep-alive
Last-Modified: Sat, 18 May 2019 08:08:16 GMT
ETag: "5cdfbd70-28"
Accept-Ranges: bytes
Length: 40 [text/html]
Remote file exists and could contain further links,
but recursion is disabled -- not retrieving.


If you want to know more, there is a very detailed article about nginx and selinux on the nginx website.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "2"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f967826%2fnginx-reverse-proxy-for-docker-swarm-502-bad-gateway%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Trying to access the backend via the reverse proxy results in a 502 Bad Gateway error:



    $ wget -S --spider http://nginxtest.example.com/
    Spider mode enabled. Check if remote file exists.
    --2019-05-18 10:12:11-- http://nginxtest.example.com/
    Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
    Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
    HTTP request sent, awaiting response...
    HTTP/1.1 502 Bad Gateway
    Server: nginx/1.12.2
    Date: Sat, 18 May 2019 08:12:11 GMT
    Content-Type: text/html
    Content-Length: 3693
    Connection: keep-alive
    ETag: "5a9e5ebd-e6d"
    Remote file does not exist -- broken link!!!


    This is most probably because selinux by default doesn't allow outgoing connections for webservers, because that's usually something they don't do.



    You will find entries like this in /var/log/nginx/error.log:




    2019/05/18 10:12:11 [crit] 1041#0: *5 connect() to 192.168.15.52:3000 failed (13: Permission denied) while connecting to upstream, client: 146.140.37.47, server: _, request: "HEAD / HTTP/1.1", upstream: "http://192.168.15.52:3000/", host: "nginxtest.example.com"




    Additionally, you will find entries like this in /var/log/audit/audit.log:




    type=AVC msg=audit(1558167131.910:463): avc: denied name_connect for pid=1041 comm="nginx" dest=3000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ntop_port_t:s0 tclass=tcp_socket permissive=0
    type=SYSCALL msg=audit(1558167131.910:463): arch=c000003e syscall=42 success=no exit=-13 a0=8 a1=562671c4eef0 a2=10 a3=7ffcfbc72530 items=0 ppid=1006 pid=1041 auid=4294967295 uid=996 gid=994 euid=996 suid=996 fsuid=996 egid=994 sgid=994 fsgid=994 tty=(none) ses=4294967295 comm="nginx" exe="/usr/sbin/nginx" subj=system_u:system_r:httpd_t:s0 key=(null)




    Run the following command to allow nginx to connect to other hosts:



    setsebool -P httpd_can_network_connect true


    (The parameter -p makes the setting persistent. Otherwise it would be reset after the next reboot.)



    And now the proxy works:



    $ wget -S --spider http://nginxtest.example.com/
    Spider mode enabled. Check if remote file exists.
    --2019-05-18 10:15:14-- http://nginxtest.example.com/
    Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
    Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
    HTTP request sent, awaiting response...
    HTTP/1.1 200 OK
    Server: nginx/1.12.2
    Date: Sat, 18 May 2019 08:15:15 GMT
    Content-Type: text/html
    Content-Length: 40
    Connection: keep-alive
    Last-Modified: Sat, 18 May 2019 08:08:16 GMT
    ETag: "5cdfbd70-28"
    Accept-Ranges: bytes
    Length: 40 [text/html]
    Remote file exists and could contain further links,
    but recursion is disabled -- not retrieving.


    If you want to know more, there is a very detailed article about nginx and selinux on the nginx website.






    share|improve this answer



























      1














      Trying to access the backend via the reverse proxy results in a 502 Bad Gateway error:



      $ wget -S --spider http://nginxtest.example.com/
      Spider mode enabled. Check if remote file exists.
      --2019-05-18 10:12:11-- http://nginxtest.example.com/
      Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
      Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
      HTTP request sent, awaiting response...
      HTTP/1.1 502 Bad Gateway
      Server: nginx/1.12.2
      Date: Sat, 18 May 2019 08:12:11 GMT
      Content-Type: text/html
      Content-Length: 3693
      Connection: keep-alive
      ETag: "5a9e5ebd-e6d"
      Remote file does not exist -- broken link!!!


      This is most probably because selinux by default doesn't allow outgoing connections for webservers, because that's usually something they don't do.



      You will find entries like this in /var/log/nginx/error.log:




      2019/05/18 10:12:11 [crit] 1041#0: *5 connect() to 192.168.15.52:3000 failed (13: Permission denied) while connecting to upstream, client: 146.140.37.47, server: _, request: "HEAD / HTTP/1.1", upstream: "http://192.168.15.52:3000/", host: "nginxtest.example.com"




      Additionally, you will find entries like this in /var/log/audit/audit.log:




      type=AVC msg=audit(1558167131.910:463): avc: denied name_connect for pid=1041 comm="nginx" dest=3000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ntop_port_t:s0 tclass=tcp_socket permissive=0
      type=SYSCALL msg=audit(1558167131.910:463): arch=c000003e syscall=42 success=no exit=-13 a0=8 a1=562671c4eef0 a2=10 a3=7ffcfbc72530 items=0 ppid=1006 pid=1041 auid=4294967295 uid=996 gid=994 euid=996 suid=996 fsuid=996 egid=994 sgid=994 fsgid=994 tty=(none) ses=4294967295 comm="nginx" exe="/usr/sbin/nginx" subj=system_u:system_r:httpd_t:s0 key=(null)




      Run the following command to allow nginx to connect to other hosts:



      setsebool -P httpd_can_network_connect true


      (The parameter -p makes the setting persistent. Otherwise it would be reset after the next reboot.)



      And now the proxy works:



      $ wget -S --spider http://nginxtest.example.com/
      Spider mode enabled. Check if remote file exists.
      --2019-05-18 10:15:14-- http://nginxtest.example.com/
      Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
      Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
      HTTP request sent, awaiting response...
      HTTP/1.1 200 OK
      Server: nginx/1.12.2
      Date: Sat, 18 May 2019 08:15:15 GMT
      Content-Type: text/html
      Content-Length: 40
      Connection: keep-alive
      Last-Modified: Sat, 18 May 2019 08:08:16 GMT
      ETag: "5cdfbd70-28"
      Accept-Ranges: bytes
      Length: 40 [text/html]
      Remote file exists and could contain further links,
      but recursion is disabled -- not retrieving.


      If you want to know more, there is a very detailed article about nginx and selinux on the nginx website.






      share|improve this answer

























        1












        1








        1







        Trying to access the backend via the reverse proxy results in a 502 Bad Gateway error:



        $ wget -S --spider http://nginxtest.example.com/
        Spider mode enabled. Check if remote file exists.
        --2019-05-18 10:12:11-- http://nginxtest.example.com/
        Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
        Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
        HTTP request sent, awaiting response...
        HTTP/1.1 502 Bad Gateway
        Server: nginx/1.12.2
        Date: Sat, 18 May 2019 08:12:11 GMT
        Content-Type: text/html
        Content-Length: 3693
        Connection: keep-alive
        ETag: "5a9e5ebd-e6d"
        Remote file does not exist -- broken link!!!


        This is most probably because selinux by default doesn't allow outgoing connections for webservers, because that's usually something they don't do.



        You will find entries like this in /var/log/nginx/error.log:




        2019/05/18 10:12:11 [crit] 1041#0: *5 connect() to 192.168.15.52:3000 failed (13: Permission denied) while connecting to upstream, client: 146.140.37.47, server: _, request: "HEAD / HTTP/1.1", upstream: "http://192.168.15.52:3000/", host: "nginxtest.example.com"




        Additionally, you will find entries like this in /var/log/audit/audit.log:




        type=AVC msg=audit(1558167131.910:463): avc: denied name_connect for pid=1041 comm="nginx" dest=3000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ntop_port_t:s0 tclass=tcp_socket permissive=0
        type=SYSCALL msg=audit(1558167131.910:463): arch=c000003e syscall=42 success=no exit=-13 a0=8 a1=562671c4eef0 a2=10 a3=7ffcfbc72530 items=0 ppid=1006 pid=1041 auid=4294967295 uid=996 gid=994 euid=996 suid=996 fsuid=996 egid=994 sgid=994 fsgid=994 tty=(none) ses=4294967295 comm="nginx" exe="/usr/sbin/nginx" subj=system_u:system_r:httpd_t:s0 key=(null)




        Run the following command to allow nginx to connect to other hosts:



        setsebool -P httpd_can_network_connect true


        (The parameter -p makes the setting persistent. Otherwise it would be reset after the next reboot.)



        And now the proxy works:



        $ wget -S --spider http://nginxtest.example.com/
        Spider mode enabled. Check if remote file exists.
        --2019-05-18 10:15:14-- http://nginxtest.example.com/
        Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
        Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
        HTTP request sent, awaiting response...
        HTTP/1.1 200 OK
        Server: nginx/1.12.2
        Date: Sat, 18 May 2019 08:15:15 GMT
        Content-Type: text/html
        Content-Length: 40
        Connection: keep-alive
        Last-Modified: Sat, 18 May 2019 08:08:16 GMT
        ETag: "5cdfbd70-28"
        Accept-Ranges: bytes
        Length: 40 [text/html]
        Remote file exists and could contain further links,
        but recursion is disabled -- not retrieving.


        If you want to know more, there is a very detailed article about nginx and selinux on the nginx website.






        share|improve this answer













        Trying to access the backend via the reverse proxy results in a 502 Bad Gateway error:



        $ wget -S --spider http://nginxtest.example.com/
        Spider mode enabled. Check if remote file exists.
        --2019-05-18 10:12:11-- http://nginxtest.example.com/
        Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
        Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
        HTTP request sent, awaiting response...
        HTTP/1.1 502 Bad Gateway
        Server: nginx/1.12.2
        Date: Sat, 18 May 2019 08:12:11 GMT
        Content-Type: text/html
        Content-Length: 3693
        Connection: keep-alive
        ETag: "5a9e5ebd-e6d"
        Remote file does not exist -- broken link!!!


        This is most probably because selinux by default doesn't allow outgoing connections for webservers, because that's usually something they don't do.



        You will find entries like this in /var/log/nginx/error.log:




        2019/05/18 10:12:11 [crit] 1041#0: *5 connect() to 192.168.15.52:3000 failed (13: Permission denied) while connecting to upstream, client: 146.140.37.47, server: _, request: "HEAD / HTTP/1.1", upstream: "http://192.168.15.52:3000/", host: "nginxtest.example.com"




        Additionally, you will find entries like this in /var/log/audit/audit.log:




        type=AVC msg=audit(1558167131.910:463): avc: denied name_connect for pid=1041 comm="nginx" dest=3000 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:ntop_port_t:s0 tclass=tcp_socket permissive=0
        type=SYSCALL msg=audit(1558167131.910:463): arch=c000003e syscall=42 success=no exit=-13 a0=8 a1=562671c4eef0 a2=10 a3=7ffcfbc72530 items=0 ppid=1006 pid=1041 auid=4294967295 uid=996 gid=994 euid=996 suid=996 fsuid=996 egid=994 sgid=994 fsgid=994 tty=(none) ses=4294967295 comm="nginx" exe="/usr/sbin/nginx" subj=system_u:system_r:httpd_t:s0 key=(null)




        Run the following command to allow nginx to connect to other hosts:



        setsebool -P httpd_can_network_connect true


        (The parameter -p makes the setting persistent. Otherwise it would be reset after the next reboot.)



        And now the proxy works:



        $ wget -S --spider http://nginxtest.example.com/
        Spider mode enabled. Check if remote file exists.
        --2019-05-18 10:15:14-- http://nginxtest.example.com/
        Resolving nginxtest.example.com (nginxtest.example.com)... 192.168.15.20
        Connecting to nginxtest.example.com (nginxtest.example.com)|192.168.15.20|:80... connected.
        HTTP request sent, awaiting response...
        HTTP/1.1 200 OK
        Server: nginx/1.12.2
        Date: Sat, 18 May 2019 08:15:15 GMT
        Content-Type: text/html
        Content-Length: 40
        Connection: keep-alive
        Last-Modified: Sat, 18 May 2019 08:08:16 GMT
        ETag: "5cdfbd70-28"
        Accept-Ranges: bytes
        Length: 40 [text/html]
        Remote file exists and could contain further links,
        but recursion is disabled -- not retrieving.


        If you want to know more, there is a very detailed article about nginx and selinux on the nginx website.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 18 at 8:23









        Gerald SchneiderGerald Schneider

        7,14732748




        7,14732748



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Server Fault!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f967826%2fnginx-reverse-proxy-for-docker-swarm-502-bad-gateway%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

            Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

            What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company