Multiple site configuration

B.R. reallfqq-nginx at
Mon May 13 16:58:48 UTC 2013

The problem I see is you try to address the process of requests differently
whether from inside your network or from the outside.
You may already solve the problem of your outside interface easily with server
names <> (knowing how nginx
processes a request <>),
listening for 'localhost', '' and ''.

What's uncommon is your way of addressing local websites, all locations
(/site2, /subsite2) inside a unique server listening on a local IP address.
That breaks the paradigm and thus becomes incompatible with the previous

The 'Mixed name-based and IP-based server names' section of the How Nginx
processes a request
provides you with intelligence on how things may be done:
server {
    listen 192.168.x.x; # Default port is 80 when not specified
    # Not sure whether or not you can use CIDR notation here, such as

    # No 'server_name' directive here, default is empty, which means all
request for this IP on port 80 without another server matching the
server_name will end up here

    # Content of site 1 here

server {
    listen 80; # Default listens on all addresses/interfaces when only a
port is specified
    server_name; # Use location redirection to remove the www in
host, see,238910,238911#msg-238911

    # Content of site 2 here

server {
    listen 80;

    # Content of site 3 here
} and will be accessible from inside/outside your
network using the same domain name.
site 1 will only be accessible from the 192.168.x.x address which shouldn't
be routed from outside your network, thus making it locally accessible
only. You may add whatever server name you wish to it, it will stick to
that network.

Another addendum: document on how Nginx choose its default server for a
particular request in How nginx processes a
request<>to learn
how nginx will address special cases.

Hope I helped.
*B. R.*

On Mon, May 13, 2013 at 12:26 PM, guillaumeserton <nginx-forum at>wrote:

> Hello,
> I would like to set nginx to use several website, and that they are
> reachable for some of them with a domain name or in localhost.
> Example:
> Site1: only accessible on localhost with 192.168.x.x/site1 (root:
> /var/www/site1)
> Site2: accessible accessible on domain and also on localhost with
> 192.168.x.x/site2 (root: /var/www/site2)
> Site3: accessible on the subdomain and also on localhost with
> 192.168.x.x/subsite2 (root: /var/www/subsite2)
> I have set two sites (site2 and site3) on my configuration and reachable
> with domain and subdomain. But i can't reach them locallly with the
> ipaddress/nameofsite. I have only one site accessible directly under my
> local ip address.
> So, currently i have:
> Site2 (var/www/site2: reachable with his domain or www.site2.euand
> also on the local ip 192.168.x.x
> SIte3 (var/www/site3: reachable with the domain Otherwise i
> can't reach him locally. I would like to reach him with 192.168.x.x/site3
> Thanks for your help.
> Posted at Nginx Forum:
> _______________________________________________
> nginx mailing list
> nginx at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list