I'm running an nginx as a reverse proxy and would like to serve apps running on an apache2 server. The app on the apache2 server is working and available via http://192.168.102:8080/ but I always get a Bad Gateway error when trying to access via the nginx proxy.

nginx config

server {
        listen 443 ssl http2;        listen [::]:443 ssl http2;
        server_name tools.domain.net;        access_log /var/log/nginx/access.log;
        client_max_body_size 100M;        large_client_header_buffers 8 32k;

       location /cctool/ {
                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;
                proxy_set_header        X-Forwarded-Host   $host:443;
                proxy_set_header        X-Forwarded-Server $host;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";

apache2 host config

<Directory /var/www/tools.domain.net>
    AllowOverride None
    Require all denied

<VirtualHost *:80>
    DocumentRoot /var/www/clients/client1/web3/web

    ServerName tools.domain.net
    ServerAdmin webmaster@tools.domain.net

    ErrorLog /var/log/ispconfig/httpd/tools.domain.net/error.log

    WSGIDaemonProcess cctool
    WSGIScriptAlias /cctool/ /var/www/support.domain.net/cctool/cctool.wsgi

    <Directory /var/www/support.domain.net/cctool/>
            WSGIProcessGroup cctool
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Require all granted
            Allow from all

nginx error log

2018/12/13 15:03:51 [error] 18695#18695: *5487204 upstream prematurely closed connection while reading response header from upstream, client:, server: tools.domain.net, request: "GET /cctool/ HTTP/1.1", upstream: "", host: "tools.domain.net"
  • This looks like your Python web app crashed during the request. Check its logs. – Michael Hampton Dec 13 '18 at 14:35
  • @MichaelHampton Are you sure about this? I already checked my logs and I couldn't find any error messages. – thpetrus Dec 13 '18 at 16:09
  • 1
    It might also be that Apache itself crashed, but that is far less likely. Though, it's not clear why you even have Apache in this setup at all; it's entirely redundant. – Michael Hampton Dec 13 '18 at 16:10
  • More info - especially about why apache "closed connection prematurely" can be found in apache log. – drookie Dec 13 '18 at 16:30

Your Answer

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

Browse other questions tagged or ask your own question.