1

I use apache as the backend server and nginx on the frontend. Apache listens to port 8080 and nginx to port 80. What I do is have the root point to the public folder foreach virtualhost:

<VirtualHost *:8080>
        ServerAdmin webmaster@localhost
        ServerName site.com
        ServerAlias site.com *.site.com
        DocumentRoot /var/www/site.com/public
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/site.com/public/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

</VirtualHost>

And here's the nginx config:

server {
        listen 80;
        access_log /var/log/nginx.access.log;
        error_log /var/log/nginx.error.log;
        root /var/www/site.com/public;
        index index.php index.html;
        server_name site.com *.site.com;
        location / {
    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8080;
            proxy_cache one;
            proxy_cache_use_stale error timeout invalid_header updating;
            proxy_cache_key $scheme$host$request_uri;
            proxy_cache_valid       200 301 302 20m;
            proxy_cache_valid       404 1m;
            proxy_cache_valid       any 15m;
    }
        }
        location ~ /\.(ht|git) {
                deny all;
        }
}

The problem is Apache resolves the domain just fine (site.com:8080), but nginx shows instead a 502 Bad Gateway (site.com:80). I tried looking at the error_log and access_log but I can't find any hint for why can't nginx work.

EDIT: The problem was I wasn't able to include that isolated config for nginx.

Jürgen Paul
  • 1,265
  • 4
  • 15
  • 22

1 Answers1

0

What user is nginx running as? It's possible that the user under which nginx is running cannot access the folder in question.

DeeDee
  • 333
  • 2
  • 7
  • 16
  • I only chowned it to: `chown -R apache:apache /var/www/site.com`. How will I know what user nginx is running as? I only run them through ssh root access. – Jürgen Paul May 30 '12 at 19:54
  • Check the nginx config file. It should be in /opt/nginx/conf/nginx.conf The Apache config file has a similar parameter. By default, Apache runs as the "apache" user. – DeeDee May 30 '12 at 19:59
  • It's obviously related to him proxying the requests, not permissions. – 3molo May 30 '12 at 20:01
  • I wouldn't be surprised if I'm wrong, but I contend that it's not obviously a proxy issue. – DeeDee May 30 '12 at 20:12
  • I'm 99% certain that you would only get a bad gateway if a backend is down. prove me wrong and I'll remove my -1 :) – 3molo May 30 '12 at 20:14
  • Well, I'm only disagreeing with the "obviously" part of your statement. If it ends up being a proxy issue, that wouldn't surprise me one bit. However, I've had this exact problem before, and it turned out to be a permissions issue. – DeeDee May 30 '12 at 20:16