Mixed Virtualhosts and IP hosts

Hello,

I have 2-3 IPs.

I would like 2 IPs to be IP based hosts, and the 3rd IP to host
my virtualhosted sites.

Currently I have setup each domain with it’s own config file
that is called into nginx.conf inside the http {} section.

The IP based hosts are working fine, but I would like to check if
I am doing things right for the virtual hosts.

Each virtual host looks like this:

server {
listen xxx.xxx.xxx.xxx;
server_name sub.domain.com www.sub.domain.com;
access_log /var/log/nginx/sub.domain.com.access.log main;

    location / {
            index   index.php index.html;
            root    /home/subdomain/public_html/images;
    }

}

So each virtualhost has the same IP.

Will this work ok ? or do all virtualhosts need to be in their
own http {} section ?

Thank you

i think you only need one http {} for each specific http “instance”

you can have hundreds of server {} blocks inside of http {} - based on
the Host: header will answer. i only have one http {} block for
hundreds of sites. if nginx is listening on all interfaces it will use
the same instance.

i do have a second http {} block for a mogilefs webdav server, only
because of the separate http configuration needed.

On Sat, Aug 30, 2008 at 08:19:11PM -0700, mike wrote:

i think you only need one http {} for each specific http “instance”

you can have hundreds of server {} blocks inside of http {} - based on
the Host: header will answer. i only have one http {} block for
hundreds of sites. if nginx is listening on all interfaces it will use
the same instance.

i do have a second http {} block for a mogilefs webdav server, only
because of the separate http configuration needed.

I never tried several http {} blocks, and I’m not sure that it will
work correctly.

On Sun, Aug 31, 2008 at 03:03:05AM +0000, David wrote:

    }

}

So each virtualhost has the same IP.

Will this work ok ? or do all virtualhosts need to be in their
own http {} section ?

You need the single http {} section with many server {} sections.
Inside server you may use any combinations of IPs, ports, and names,
they
should work as one may expect. If there are duplicates names on some IP,
nginx will warn you and ignore the duplicate.

On 8/30/08, Igor S. [email protected] wrote:

I never tried several http {} blocks, and I’m not sure that it will
work correctly.

really? works fine from my perspective - here’s my config. seems to work
great.

i thought that was the whole point, is you can have multiple services
as needed (http, imap or whatever, etc) - i guess i’d take any
optimization pointers, i’m always interested in simplifying
configurations and optimization!

user www-data www-data;
worker_processes 2;
worker_cpu_affinity 0001 0010;
worker_rlimit_nofile 131072;
working_directory /var/run;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
ignore_invalid_headers on;
client_max_body_size 251m;
client_header_buffer_size 8k;
client_body_buffer_size 256k;
large_client_header_buffers 16 8k;
keepalive_timeout 30;
server_tokens off;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $http_host;
fastcgi_param REDIRECT_STATUS 200;
fastcgi_ignore_client_abort on;
fastcgi_buffers 16 16k;
fastcgi_index index.php;
fastcgi_intercept_errors on;

    gzip on;
    gzip_static on;
    gzip_proxied any;
    gzip_min_length 1100;
    gzip_buffers 16 8k;
    #gzip_http_version 1.0;
    gzip_comp_level 4;
    gzip_types text/plain text/css application/x-javascript

text/xml application/xml application/xml+rss text/javascript;
gzip_disable “MSIE [1-6].”;
gzip_vary on;

    server_names_hash_max_size 4096;
    server_names_hash_bucket_size 128;

    server {
            listen 80;
            all my server stuff here
            tons of server blocks
    }

}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 0;
tcp_nodelay on;
client_max_body_size 251m;
client_body_temp_path /var/mogdata/.tmp;
server_tokens off;
server {
access_log off;
listen 7500;
server_name localhost;
charset utf-8;
location / {
root /var/mogdata/;
dav_methods put delete mkcol copy move;
dav_access user:rw group:rw all:r;
# not sure if this is needed
create_full_put_path on;
}
# these are not right
error_page 500 502 503 504 /50x.html;
location /50x.html {
root html;
}
}
}

On Sun, Aug 31, 2008 at 11:17:50AM +0400, Igor S. wrote:

optimization pointers, i’m always interested in simplifying
configurations and optimization!

You may use http and main sections in one configuraiton, but several http’s
are not intended by design. Probably they sould work, I will investigate.

I have found the case that will not work: in the following configuration
all requests to 80 port will go to one server only, despite the Host
header:

http {
server {
listen 80;
server_name one;
}
}

http {
server {
listen 80;
server_name two;
}
}

So several http{} sections are not supported configuration.

I am totally fine with just making an additional server {} block
instead of http {}

This is pretty much the only configuration option I’d want to change:
client_body_temp_path /var/mogdata/.tmp;

would this work? I guess the more I think about it I don’t care where
it puts the temp files… I just know that /var/mogdata/.tmp works
nicely for the mogilefs stuff.

       server {
                  access_log off;
                  listen 7500;
                  server_name localhost;
                  client_body_temp_path /var/mogdata/.tmp;
                  charset utf-8;
                  location / {
                          root /var/mogdata/;
                          dav_methods put delete mkcol copy move;
                          dav_access user:rw group:rw all:r;
                          create_full_put_path on;
                  }
       }

On 8/31/08, Igor S. [email protected] wrote:

http {
server {
listen 80;
server_name two;
}
}

So several http{} sections are not supported configuration.

That makes sense, this seemed logical because it was a different port.
It does seem to work though, but server {} allows for a different port
anyway, so I think I don’t even need it.

On Sat, Aug 30, 2008 at 11:58:39PM -0700, mike wrote:

On 8/30/08, Igor S. [email protected] wrote:

I never tried several http {} blocks, and I’m not sure that it will
work correctly.

really? works fine from my perspective - here’s my config. seems to work great.
i thought that was the whole point, is you can have multiple services
as needed (http, imap or whatever, etc) - i guess i’d take any
optimization pointers, i’m always interested in simplifying
configurations and optimization!

You may use http and main sections in one configuraiton, but several
http’s
are not intended by design. Probably they sould work, I will
investigate.

seems to work well - just took out that second http {} block and put
it in the first one and it seems to be functional still for mogilefs.

cool!

On Sun, Aug 31, 2008 at 12:30:14AM -0700, mike wrote:

                          create_full_put_path on;
                  }
       }

Yes, you may set/override client_body_temp_path on http/server/locaiton
level.

That’s basically what I’ve done with the nginx config for
mogilefs, only a little different:

http {

server {
listen 7500;
server_name localhost;

     charset utf-8;

     location /dev1 {
         root   /var/mogdata;
         client_body_temp_path /var/mogdata/dev1;
         dav_methods put delete mkcol copy move;
         dav_access user:rw group:rw all:r;
     }

     location /dev2 {
         root   /var/mogdata;
         client_body_temp_path /var/mogdata/dev2;
         dav_methods put delete mkcol copy move;
         dav_access user:rw group:rw all:r;
     }
  }

}

  Each /dev is actually a dedicated disk with the same name.

Doing it that way lets you load up a box or add disks at will. Not to
go way off topic on mogilefs.


Scott Larson
Network Administrator

Wiredrive
4216 3/4 Glencoe Ave
Marina Del Rey, CA 90292
t 310.823.8238
[email protected]
http://www.wiredrive.com

i only have one device on those servers.

however, i do have

    location /dev4 {
        root /var/mogdata/;
        client_body_temp_path /var/mogdata/dev4/.tmp;
        dav_methods put delete mkcol copy move;
        dav_access user:rw group:rw all:r;
        # not sure if this is needed
        create_full_put_path on;
    }
    location /dev5 {
        root /var/mogdata/;
        client_body_temp_path /var/mogdata/dev5/.tmp;
        dav_methods put delete mkcol copy move;
        dav_access user:rw group:rw all:r;
        # not sure if this is needed
        create_full_put_path on;
    }

on a server that does have two devices.

and i guess i answered a previous question - you could use a different
client_body_temp_path. funny how i already figured that out in the
last and forgot it :slight_smile: (igor already told me a second time, but
apparently i had it figured out on my own)

so according to your config you don’t have the “create_full_put_path”
and it still works like a charm? i am not using mine in production
yet, i assume you are…

I did that example off the top of my head, but yes I do have
create_full_put_path enabled, it was more an example of using location
to enable the use of multiple devices in a config. The
client_body_temp_path is important if each location is at a separate
physical mount point otherwise you’ll run into nginx not writing data.

Scott Larson
Network Administrator

Wiredrive
4216 3/4 Glencoe Ave
Marina Del Rey, CA 90292
t 310.823.8238
[email protected]
http://www.wiredrive.com

okay. cool. i’m going to remove my comment that says “might not need
this” then :slight_smile:

Thanks for your replies guys. Will start transferring the domains and
see how it
goes :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs