Question

nginx+apache = 502 error

  • Posted February 26, 2014

hello i have finished settupng my droplet with this article: https://digitalocean.com/community/articles/how-to-configure-nginx-as-a-front-end-proxy-for-apache, but after restarting their services i got 502 error - Bad Gateway.

netstat output: Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 27867/mysqld tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5846/nginx tcp 0 0 127.0.0.1:82 0.0.0.0:* LISTEN 5824/apache2 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 793/sshd tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 13573/php-fpm.conf) tcp6 0 0 :::4949 :::* LISTEN 24573/munin-node tcp6 0 0 :::22 :::* LISTEN 793/sshd

/etc/nginx/sites-enabled/myexamplesite config: server { listen 80;

    root /var/www/;
    index index.php index.html index.htm;

    server_name myexamplesite.com;

    location / {
    try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {

    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8080;

     }

     location ~ /\.ht {
            deny all;
    }

}

/etc/apache2/sites-enabled/myexamplesite config: <VirtualHost 127.0.0.1:82> ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>

what is wrong here? it seems that request passes nginx to apache but than something goes wrong

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

<pre>proxy_pass http://127.0.0.1:8080;</pre> You are trying to reverse proxy requests to 127.0.0.1:8080 but I don’t see anything listening on that port.

try to restar php service <br>alternatively (is that a word?) try changin <br>try_files $uri $uri/ /index.php;
<br>to try_files $uri /index.php?$args; <br>