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

I have this setup with apache but want to move over to nginx. I'm not sure how I can accomplish this.

In apache I had it as ServerAlias *

What would be the nginx equivalent?

I've tried server_name www.example.net default_server; and server_name _; but that doesn't seem to work. I just keep getting a 404 every time I visit any host but www.example.com.

Update It seems that serving static files is not a problem. So it is pointing correctly but PHP files are giving me a 404 error (using php-fpm). Any ideas?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Does the user for the php-fpm pool have the right permissions to read the PHP files in the directory? i.e. if Nginx is running as www-data:www-data (as mine does) but your php-fpm pool is running as "user:user", then does the "user" account have the right permissions on the webroot to be able to open the PHP files?

share|improve this answer
    
Yes it does. Using www.example.com/index.php I can see what I'm supposed to be seeing. When I try to access it using foo.example.com/index.php I get a 404 error. –  Meisam Mulla May 24 '12 at 8:02
    
Sounds like checking the php-fpm and/or nginx logs is the only way forward then, I haven't used your setup specifically but I see no reason why it shouldn't work. –  gac May 24 '12 at 8:04
    
I see this error in the nginx error log: 2012/05/24 08:06:04 [error] 32072#0: *17 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 96.48.131.149, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock:", host: "foo.example.com" 2012/05/24 08:06:04 [error] 32072#0: *17 open() "/home/example/frontend/50x.html" failed (2: No such file or directory), client: 96.48.131.149, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock:", host: "foo.example.com" Any ideas? –  Meisam Mulla May 24 '12 at 8:12
    
Ok it seems like the problem is with my php script itself. However I am unable to tell what the error is exactly. –  Meisam Mulla May 24 '12 at 8:20
    
Found the issue instead of giving a 500 error it was showing a 404. –  Meisam Mulla May 24 '12 at 8:56

Apparently an invalid server_name like _ should serve as a catch all virtual host.

share|improve this answer

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.