I would like to serve multiple sites on one instance.

I install nginx, php-fpm, and a rails app. I use sites like this to guide me.

I configure php-fpm to listen to a local socket

listen = /var/run/php-fpm/php-fpm.sock

I configure ngnix with multiple hosts:

include /etc/nginx/conf.d/*.conf

I have several site php conf files like /etc/nginx/conf.d/site1.conf

server {
    listen 80; 
    server_name site1.com www.site1.com;

    root /var/www/site1;

    access_log /var/log/nginx/site1.com-access.log;
    error_log /var/log/nginx/site1.com-error.log;

    location / { 
        index index.html index.php;
    location ~ \.php$ {
        fastcgi_pass        unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index       index.php;
        include             fastcgi_params;
        fastcgi_param       PATH_INFO $fastcgi_script_name;
        fastcgi_param       SCRIPT_FILENAME $document_root/$fastcgi_script_name;

and rails site conf files like

upstream rails {

server {
    listen 80;
    server_name site2.com www.site2.com;

    access_log /var/log/nginx/site2.com-access.log;
    error_log /var/log/nginx/site2.com-error.log;

    root /var/www/site2;

    location / {
        proxy_pass                       http://rails;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host            $host;
        proxy_set_header X-Url-Scheme    $scheme;

I have a unicorn rails server running via rails s -p 3000

Yet, no sites come up for either site1.com or site2.com. I can get to the rails site at www.site2.com:3000

What is wrong? I've spent 2 days (nearly 30hr) trying many different blogs, SO / SF questions, etc. Please share your insight or answer.

edit 1: No log entries are created when I try to visit either site. It's like the requests never come in.

  • I don't see any error messages or log entries. What errors did you receive and what was logged? Sep 4, 2012 at 5:37
  • @MichaelHampton the logs are empty for these requests. (there's only older stuff for upstream misconfigurations I had made before) Sep 4, 2012 at 14:32
  • Because you didn't specify an error_log directive.
    – quanta
    Sep 4, 2012 at 15:42
  • @quanta i did, I just thought I"d simplify the code in my question. I've re-added it for 'certainty' Sep 4, 2012 at 16:20
  • 1
    Append debug to the end of error_log line, try again and post the logs here.
    – quanta
    Sep 4, 2012 at 16:24

1 Answer 1


Always check your firewall / proxy / incoming ports.

Everything in the above config files works perfectly fine. The problem was that port 80 wasn't open to inbound traffic.

  • I am running a rails application on free instance of EC2 with Nginx + Unicorn. When I try to access public url, I am getting 404. I verified that Nginx + Unicorn configuration is ok. Here is security group rules which is selected for the instance. What else I have to check?
    – Amit Patel
    Mar 20, 2015 at 6:41
  • You should ask this as new question, rather than posting a comment. That's the site best practices. Thanks! Mar 20, 2015 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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