Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Nothing looks wrong, and you decided not to include the log so it's hard to help... –  gparent May 30 '12 at 19:49
    
bad gateway suggests that you proxy_pass (or fastcgi_pass etc). Where's that piece of config? –  3molo May 30 '12 at 19:50
    
the log is empty :( –  Pineapple Under the Sea May 30 '12 at 19:52
    
@3molo hi thanks, I just included it. –  Pineapple Under the Sea May 30 '12 at 19:53
    
Is apache listening to your non localhost ip, or to all ips? (if all ips, are there any firewall rules?) –  3molo May 30 '12 at 19:55

1 Answer 1

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

share|improve this answer
    
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. –  Pineapple Under the Sea 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.