# Nginx as backend

**URL:** <https://www.ruby-forum.com/t/nginx-as-backend/224220>\
**Category:** NGINX\
**Created:** [November 3, 2012, 7:19pm UTC](https://www.ruby-forum.com/t/nginx-as-backend/224220 "2012-11-03T19:19:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 3, 2012, 7:19pm UTC](https://www.ruby-forum.com/t/nginx-as-backend/224220/1 "2012-11-03T19:19:32Z")

</div>

Hi,

I am writing this to hopefully get some help of you gus after  
struggeling with this issue in a few days.

I will try to describe the issue as short as pssible.

Ok, my website runs just fine on 443 and 80 with the lastest version on  
nginx. (thx Igor and Nginx team!)

The problem started when I tried to put varnish (port 80) in front of  
Nginx (port 81).

1- Of some reason I have to start Nginx before starting varnish  
otherwise I get bind() to 0.0.0.0:80 failed (98: Address already in  
use)… (yes yes I’ve already checked the config out and I’ve changed  
the port to 81)

2- When i start start Nginx first and varnish after, both softwares  
start to run, my site works just fine on 443 (https) but using http,  
nginx shows /usr/local/nginx/html/index.htm instead of  
/var/www/domain.com/index.php

lsof -i tcp:80  
nginx 1071 root 10u IPv4 4296 0t0 TCP \*:www (LISTEN)  
nginx 1073 www-data 10u IPv4 4296 0t0 TCP \*:www (LISTEN)  
nginx 1074 www-data 10u IPv4 4296 0t0 TCP \*:www (LISTEN)  
nginx 1075 www-data 10u IPv4 4296 0t0 TCP \*:www (LISTEN)  
varnishd 1093 nobody 6u IPv6 4347 0t0 TCP \*:www (LISTEN)

lsof -i tcp:81  
nginx 1071 root 8u IPv4 4294 0t0 TCP \*:81 (LISTEN)  
nginx 1073 www-data 8u IPv4 4294 0t0 TCP \*:81 (LISTEN)  
nginx 1074 www-data 8u IPv4 4294 0t0 TCP \*:81 (LISTEN)  
nginx 1075 www-data 8u IPv4 4294 0t0 TCP \*:81 (LISTEN)

here is my config files

user www-data;  
worker\_processes 1;  
error\_log /var/log/nginx/error.log warn;  
pid /var/run/nginx.pid;  
events {  
worker\_connections 1024;  
}  
http {  
set\_real\_ip\_from 127.0.0.1;  
real\_ip\_header X-Forwarded-For;  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;  
sendfile on;  
include /etc/nginx/conf.d/\*.conf;  
port\_in\_redirect off;  
}  
\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<  
default  
server {  
listen 81 default; ## listen for ipv4  
set\_real\_ip\_from 127.0.0.1;  
real\_ip\_header X-Forwarded-For;  
server\_name \_;  
root /var/www/domain.com;  
location / {  
root /var/www/defaultdir;  
index index.php index.html index.htm;  
}  
location ~ .php$ {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
}  
}  
\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<\<

> **[Website Domain Names, Online Stores & Hosting](https://www.domain.com/)**
>
> Finding the perfect website domain is as easy as 1-2-3. Buy a domain name, build and host a website, and enjoy our professional online marketing tools.

server {  
server\_name .domain.com;  
root /var/www/domain.com;  
listen 81;  
set\_real\_ip\_from 127.0.0.1;  
real\_ip\_header X-Forwarded-For;  
listen 443 ssl;  
{SSL stuffs goes here}

location / {  
index index.php index.html index.htm;  
access\_log off;  
error\_log off;  
}  
location ~ .php$ {  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
include fastcgi\_params;  
fastcgi\_param HTTPS on;

}  
}

I would appreciate any help I can get with this issue.

Best regards, Mat
