0

i have a Nginx Front End Server running on Centos9 on 10.0.100.6 and different docker Containers in the backend.

The docker container working fine i can acess them ez via port number BUT my nginx reverse Proxy configuration not working and i get this red site 500 alarm which saying Site temporally unavailable.

My configuration looks like this ( I just using http because this is just for demonstration/testing) :


server {
listen 80;
listen [::]:80;
server_name localhost;

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

location /nextcloud {
proxy_pass http://10.0.100.6:8080/;
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;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
} 

nginx -T

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#        location = /404.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#        location = /50x.html {
#        }
#    }

}


# configuration file /etc/nginx/mime.types:

types {
    text/html                                        html htm shtml;
    text/css                                         css;
    text/xml                                         xml;
    image/gif                                        gif;
    image/jpeg                                       jpeg jpg;
    application/javascript                           js;
    application/atom+xml                             atom;
    application/rss+xml                              rss;

    text/mathml                                      mml;
    text/plain                                       txt;
    text/vnd.sun.j2me.app-descriptor                 jad;
    text/vnd.wap.wml                                 wml;
    text/x-component                                 htc;

    image/avif                                       avif;
    image/png                                        png;
    image/svg+xml                                    svg svgz;
    image/tiff                                       tif tiff;
    image/vnd.wap.wbmp                               wbmp;
    image/webp                                       webp;
    image/x-icon                                     ico;
    image/x-jng                                      jng;
    image/x-ms-bmp                                   bmp;

    font/woff                                        woff;
    font/woff2                                       woff2;

    application/java-archive                         jar war ear;
    application/json                                 json;
    application/mac-binhex40                         hqx;
    application/msword                               doc;
    application/pdf                                  pdf;
    application/postscript                           ps eps ai;
    application/rtf                                  rtf;
    application/vnd.apple.mpegurl                    m3u8;
    application/vnd.google-earth.kml+xml             kml;
    application/vnd.google-earth.kmz                 kmz;
    application/vnd.ms-excel                         xls;
    application/vnd.ms-fontobject                    eot;
    application/vnd.ms-powerpoint                    ppt;
    application/vnd.oasis.opendocument.graphics      odg;
    application/vnd.oasis.opendocument.presentation  odp;
    application/vnd.oasis.opendocument.spreadsheet   ods;
    application/vnd.oasis.opendocument.text          odt;
    application/vnd.openxmlformats-officedocument.presentationml.presentation
                                                     pptx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                                     xlsx;
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                                     docx;
    application/vnd.wap.wmlc                         wmlc;
    application/wasm                                 wasm;
    application/x-7z-compressed                      7z;
    application/x-cocoa                              cco;
    application/x-java-archive-diff                  jardiff;
    application/x-java-jnlp-file                     jnlp;
    application/x-makeself                           run;
    application/x-perl                               pl pm;
    application/x-pilot                              prc pdb;
    application/x-rar-compressed                     rar;
    application/x-redhat-package-manager             rpm;
    application/x-sea                                sea;
    application/x-shockwave-flash                    swf;
    application/x-stuffit                            sit;
    application/x-tcl                                tcl tk;
    application/x-x509-ca-cert                       der pem crt;
    application/x-xpinstall                          xpi;
    application/xhtml+xml                            xhtml;
    application/xspf+xml                             xspf;
    application/zip                                  zip;

    application/octet-stream                         bin exe dll;
    application/octet-stream                         deb;
    application/octet-stream                         dmg;
    application/octet-stream                         iso img;
    application/octet-stream                         msi msp msm;

    audio/midi                                       mid midi kar;
    audio/mpeg                                       mp3;
    audio/ogg                                        ogg;
    audio/x-m4a                                      m4a;
    audio/x-realaudio                                ra;

    video/3gpp                                       3gpp 3gp;
    video/mp2t                                       ts;
    video/mp4                                        mp4;
    video/mpeg                                       mpeg mpg;
    video/quicktime                                  mov;
    video/webm                                       webm;
    video/x-flv                                      flv;
    video/x-m4v                                      m4v;
    video/x-mng                                      mng;
    video/x-ms-asf                                   asx asf;
    video/x-ms-wmv                                   wmv;
    video/x-msvideo                                  avi;
}

# configuration file /etc/nginx/conf.d/nextcloud.conf:
server {
    listen 80;
    listen [::]:80;
    listen 10.0.100.6:80;
    server_name localhost;

    location / {
        proxy_buffering off;
        proxy_pass http://localhost:8080/apps/dashboard/;
        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;
        }
    
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;
                    }
}


Can you help me with this? I'm realy stuck here!

Edit:

After some log searching i found this in the Nginx logs:

2024/01/31 10:53:26 [crit] 110426#110426: *7 connect() to 10.0.100.6:8080 failed (13: Permission denied) while connecting to upstream, client: 10.0.100.144, server: localhost, request: "GET / HTTP/1.1", upstream: "http://10.0.100.6:8080/", host: "10.0.100.6"

4
  • Do you use docker compose? Can you please provide the configuration of your docker containers? Also please do `nginx -T' and provide the output. And enable error and access logging and review the logs. You can also use a docker container as reverse proxy, make sure it's in the same docker network as your other containers
    – Turdie
    Commented Jan 30 at 17:06
  • Hey thx postet the nginx -T config its slightly different know because i tested a lot of configs but nothing worked . The point is it not just working with nextcloud its not working with wordpress 2 . I can access them ez on 10.0.100.6:8080 AND 10.0.100.6:8888 . Logs just saying i restarted the nginx service and configuration is correct. I try your post now and give you reply if it worked
    – naseweis
    Commented Jan 30 at 17:32
  • What is the output of getsebool httpd_can_network_connect? Commented Jan 31 at 10:51
  • And getsebool httpd_can_network_relay please. Commented Jan 31 at 10:59

4 Answers 4

2

The culprit is most likely SELinux, where network operations of services are restricted by default.

As documented you can use these two commands to enable network access for nginx permanently:

setsebool httpd_can_network_connect 1 -P
# or
setsebool httpd_can_network_relay 1 -P

If you only want to enable it temporarily (for testing purposes) omit the -P

For httpd_can_network_relay you will most likely need to extend the http_port_t port list with semanage port, as shown in the documentation. I would prefer this option, as it reduces the attack surface of the overall installation.

1
  • THX man it brought me closer now i'm seeing 400 bad request Request Header or Cookie to Large
    – naseweis
    Commented Jan 31 at 12:38
0

(should be a comment but space limited/no formatting)

and i get this red site 500 alarm which saying Site temporally unavailable.

Hmmm. And is that the file at /usr/share/nginx/html/500.html ? Did you check your logs?

The first thing you should be doing is determining whether the error is being reported by the proxy or the origin host.

I suspect that the proxy may be working fine - but your docker application doesn't like the traffic you are sending it.

1
  • Hey checked docker logs but the application just recieving the calls i get when i directly address them over the port number not from the proxy . yea could be both but the strange thing is i have the same problem with wordpress ...
    – naseweis
    Commented Jan 30 at 17:36
0

I found this article and he also faced some issues with nextcloud and shared his config, hopefully that helps https://zuckerbude.org/nextcloud-behind-reverse-proxy/

server {
    server_name nc.example.com;
    location / {
    proxy_set_header  Host $host;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-Proto https;
    proxy_set_header  X-Forwarded-Host $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://10.10.10.178:80;
    proxy_buffers 16 4k;
    proxy_buffer_size 2k;
    }

    location /.well-known/carddav {
      return 301 $scheme://$host/remote.php/dav;
    }

    location /.well-known/caldav {
      return 301 $scheme://$host/remote.php/dav;
    }

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/nc.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/nc.example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
}

server {
    if ($host = nc.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name nc.example.com;
    listen [::]:80;
    listen 80;
    return 404; # managed by Certbot
}

Edit

Can you please enable detailed access logs and also include access logs in your server block

http {
    # ... other http block configurations ...

    log_format detailed '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    server {
        # ... other server block configurations ...

        access_log /var/log/nginx/access.log detailed;
    }
}

And then restart nginx

service nginx restart 
3
  • Hey i rwrote to my purpose just using http right now and now nginx saying 502 bad gateway the nextcloud container not recieving the get request as logs saying :( I'm now out of office but thx for all your help coming back tommorow :)
    – naseweis
    Commented Jan 30 at 17:44
  • I think nextcloud requires https, after some research on the internet. So please try with https
    – Turdie
    Commented Jan 30 at 17:47
  • hey i can't i have no domain and as i said if i type 10.0.100.6:8080 in My Webbrowser its working so i can address the ports but just the proxy is not working
    – naseweis
    Commented Jan 30 at 17:49
0

thx my reverse proxy is working .

setsebool httpd_can_network_connect 1 -P `setsebool httpd_can_network_relay 1 -P

did the first trick and than i had to add

large_client_header_buffers 4 16k;

So my nginx config looks like this

server {
    server_name localhost;
    large_client_header_buffers 4 16k;
    
    
     location /nextcloud {
    proxy_set_header  Host $host;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-Proto http;
    proxy_set_header  X-Forwarded-Host $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://10.0.100.6:8080;

    }

     location /wordpress {
    proxy_set_header  Host $host;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-Proto http;
    proxy_set_header  X-Forwarded-Host $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://10.0.100.6:8888;
    
    }

    location /.well-known/carddav {
      return 301 $scheme://$host/remote.php/dav;
    }

    location /.well-known/caldav {
      return 301 $scheme://$host/remote.php/dav;
    }

    listen [::]:80;
    listen 80; 
}

Just in case someone struggeling to. My applications still need some adjustments. But thx on all of you helping me running the reverse proxy :))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .