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 am trying to setup nginx to be in front of apache and serve all static files and then send everything else to apache. I almost have it fully working, static content is being served by nginx and example.com/ is being proxied to apache. But everything else, like example.com/bla, isn't. I get a 'not found' page served by nginx(I checked the headers to see if it was nginx or apache giving me the error page) instead of it being proxied to apache.

I have took out all the static content handling, in case that was causing problems.

According to everything I've read, location / { should match everything when nothing else matches. But then how come example.com/bla doesn't work when there are no other location matches? Anyone have any ideas? Am I missing something?

nginx.conf

user web;
worker_processes 1; #one for each core good idea
error_log /var/log/nginx/error.log warn;
pid       /var/run/nginx.pid;
events {
       worker_connections 1024;
}
http {
     include    /etc/nginx/mime.types;
     log_format main    '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for"';
     access_log /var/log/nginx/access.log main;
     sendfile   on;
     keepalive_timeout  3; 
     include /etc/nginx/conf.d/*.conf;
}

conf.d/web.conf:

server {
       listen           80;
       server_name      example.com;

       charset utf-8;

       location  / {
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr; 
                proxy_set_header Host $host;
                proxy_redirect off;
                proxy_max_temp_file_size 0; 
                proxy_pass http://127.0.0.1:8081;                
       }
}
share|improve this question
    
Looks like we're missing some config - where's the config that's setting static files to be served locally? –  Shane Madden Mar 2 '12 at 16:59
    
I took that part out of the config for the moment to see if that was part of the problem or not. –  Echo Mar 2 '12 at 17:08
    
Did you restart nginx and clear the cache on your browser after removing it? –  Shane Madden Mar 2 '12 at 17:09
    
Yes, I did restart nginx and clear the cache. –  Echo Mar 2 '12 at 17:11
    
Something weird is going on... I rebooted the server and accessed example.com/bla before bringing apache back up and I got a gateway error. Then I started apache back up and then get the 404 from nginx at that url. Looks like the location does not have problem, must be something else. –  Echo Mar 2 '12 at 17:18

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.