# nginx und Rails (ISPC3)



## Quest (27. Sep. 2012)

Hallo zusammen.

ich habe ein lustiges Problem.
Einer der Server im Multiserversetup ist mit nginx als Webserver aufgesetzt und soll auch mit Hilfe von Thin Rails-Apps ausliefern.
Aktuell laufen auf dem System 2 Rails Seiten. 

Interessant ist, dass diese Seiten auf beiden Domains nach dem Zufallsprinzip abwechselnd ausgegeben werden.
Ich weiß hier wirklich nicht mehr weiter.
In der Hoffnung, dass mir von euch jemand helfen kann poste ich hier alle relevanten Config-Files:

/etc/nginx/proxy.include (bei den Hosts eingebunden)

```
proxy_set_header   Host $http_host;                                                              
    proxy_set_header   X-Real-IP $remote_addr;                                                       
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;

    client_max_body_size       10m;
    client_body_buffer_size    128k;

    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;

    proxy_buffer_size          4k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size 64k;
```
/etc/nginx/sites-availible/site1.com.vhost

```
server {
        listen *:80;


        server_name site1.com;


        index index.html index.htm index.php index.cgi index.pl index.xhtml;



        error_page 400 /error/400.html;
        error_page 401 /error/401.html;
        error_page 403 /error/403.html;
        error_page 404 /error/404.html;
        error_page 405 /error/405.html;
        error_page 500 /error/500.html;
        error_page 502 /error/502.html;
        error_page 503 /error/503.html;
        recursive_error_pages on;
        location = /error/400.html {
            internal;
        }
        location = /error/401.html {
            internal;
        }
        location = /error/403.html {
            internal;
        }
        location = /error/404.html {
            internal;
        }
        location = /error/405.html {
            internal;
        }
        location = /error/500.html {
            internal;
        }
        location = /error/502.html {
            internal;
       }

        error_log /var/log/ispconfig/httpd/site1.com/error.log;
        access_log /var/log/ispconfig/httpd/site1.com/access.log combined;

        ## Disable .htaccess and other hidden files
        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
        }

        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }

        location /stats {
            index index.html index.php;
            auth_basic "Members Only";
            auth_basic_user_file /var/www/clients/client1/web57/.htpasswd_stats;
        }

        location ^~ /awstats-icon {
            alias /usr/share/awstats/icon;
        }

        location ~ \.php$ {
            deny all;
        }


        include /etc/nginx/proxy.include;
        root /var/www/clients/client1/web57/web/public;
        proxy_redirect off;
        location / {
        try_files $uri/index.html $uri.html $uri @cluster;
        }
            location @cluster {
                proxy_pass http://thin_cluster;
            }
        }
        upstream thin_cluster {
            server unix:/var/www/clients/client1/web57/web/tmp/sockets/site1.com.0.sock;
            server unix:/var/www/clients/client1/web57/web/tmp/sockets/site1.com.1.sock;
            server unix:/var/www/clients/client1/web57/web/tmp/sockets/site1.com.2.sock;
            server unix:/var/www/clients/client1/web57/web/tmp/sockets/site1.com.3.sock;

}
```
/etc/nginx/sites-availible/site2.com.vhost

```
server {
        listen *:80;


        server_name site2.com ;


        index index.html index.htm index.php index.cgi index.pl index.xhtml;



        error_log /var/log/ispconfig/httpd/site2.com/error.log;
        access_log /var/log/ispconfig/httpd/site2.com/access.log combined;

        ## Disable .htaccess and other hidden files
        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
        }

        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }

        location /stats {
            index index.html index.php;
            auth_basic "Members Only";
            auth_basic_user_file /var/www/clients/client1/web64/.htpasswd_stats;
        }

        location ^~ /awstats-icon {
            alias /usr/share/awstats/icon;
        }

        location ~ \.php$ {
            deny all;
        }

        include /etc/nginx/proxy.include;
        root /var/www/clients/client1/web64/web/public;
        proxy_redirect off;
        location / {
        try_files $uri/index.html $uri.html $uri @cluster;
        }
            location @cluster {
                proxy_pass http://thin_cluster;
                auth_basic "Developers Only";
                auth_basic_user_file /var/www/clients/client1/web64/web/.htpasswd;
            }
        }
        upstream thin_cluster {
            server unix:/var/www/clients/client1/web64/web/tmp/sockets/site2.com.0.sock;
            server unix:/var/www/clients/client1/web64/web/tmp/sockets/site2.com.1.sock;

}
```
/etc/thin/site1.com.yml

```
pid: tmp/pids/site1.com.pid
group: client1
wait: 30
timeout: 30
log: log/site1.com.log
max_conns: 1024
require: []

environment: production
max_persistent_conns: 512
servers: 4
daemonize: true
user: web57
#socket: /tmp/site1.com.sock
socket: /var/www/clients/client1/web57/web/tmp/sockets/site1.com.sock
chdir: /var/www/clients/client1/web57/web
```
/etc/thin/site2.com.yml

```
pid: tmp/pids/site2.com.pid
group: client1
wait: 30
timeout: 30
log: log/site2.com.log
max_conns: 1024
require: []

environment: development
max_persistent_conns: 512
servers: 2
daemonize: true
user: web64
socket: /var/www/clients/client1/web64/web/tmp/sockets/site2.com.sock
chdir: /var/www/clients/client1/web64/web
```


----------

