nginx+apache = 502 error

  • Posted February 26, 2014

hello i have finished settupng my droplet with this article:, 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* LISTEN 27867/mysqld tcp 0 0* LISTEN 5846/nginx tcp 0 0* LISTEN 5824/apache2 tcp 0 0* LISTEN 793/sshd tcp 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;


    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;


     location ~ /\.ht {
            deny all;


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

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

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

    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 ::1/128


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


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;</pre> You are trying to reverse proxy requests to 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>