Hello,
on my server I have several IP-Addresses and for some of them I want to
use Nginx to server port 80. I want to host several different domains.
Let’s say A.org and B.org to IP-Address 1.1.1.1:80 and C.org to
IP-Address 1.1.1.2:80, while 1.1.1.3:80 shall not be used by Nginx.
Shall I configure Nginx something like
server {
listen 1.1.1.1;
server_name A.org B.org;
if ($host ~ “A.org”) {root /A; … break;}
if ($host ~ “B.org”) {root /B;… break;}
}
server {
listen 1.1.1.2;
server_name C.org;
}
or is there a way to configure three different server{}s?
server { server_name A.org; }
server { server_name B.org; }
server { server_name C.org; listen 1.1.1.2; }
In the former form, I cannot use directly “root /A;” in if ().
In the latter form, I cannot use for A.org and B.org listen 1.1.1.1, as
Nginx says it cannot bind twice IP1.1.1.1 (it can bind to it for A, but
since the socket is already occupied, it cannot bind for for B.org}.
Moreover, as the Nginx module documentation is available both trough
wiki.nginx.org (wiki.nginx.org/HttpCoreModule) and
nginx documentation, I would like to ask which is the
reference documentation (and what is the point to have the documentation
on two different places – e.g. why isn’t the wiki enough).
nginx version: nginx/1.0.15
TLS SNI support enabled
configure arguments: --pid-path=/var/run/nginx.pid
–conf-path=/etc/nginx/core.conf
–error-log-path=/var/log/nginx/nginx.log --user=wwwrun --group=nogroup
–with-ipv6 --without-poll_module --without-select_module
–with-file-aio --with-http_ssl_module --with-http_addition_module
–with-http_xslt_module --with-http_image_filter_module
–with-http_sub_module --with-http_dav_module --with-http_flv_module
–with-http_mp4_module --with-http_gzip_static_module
–with-http_random_index_module --with-http_degradation_module
–with-http_stub_status_module --http-log-path=/var/log/nginx
–with-pcre --prefix=/usr --with-cc-opt=‘-O3 -march=native
-Wl,–hash-style=gnu -Wl,-O1 -flto -Wl,-z,relro’
–with-ld-opt=‘-L/usr/lib64 -L/lib64’ --without-http_ssi_module
–without-http_uwsgi_module --without-http_scgi_module
–without-http_upstream_ip_hash_module
–without-http_split_clients_module --without-http_empty_gif_module
Thanks in advance for your help
Дилян
2012/4/14 Дилян Палаузов [email protected]:
server_name A.org B.org;
if ($host ~ “A.org”) {root /A; … break;}
if ($host ~ “B.org”) {root /B;… break;}
}
This is a really nasty way of dealing with vhosts. I don’t know
offhand if it’s even valid.
or is there a way to configure three different server{}s?
server { server_name A.org; }
server { server_name B.org; }
server { server_name C.org; listen 1.1.1.2; }
In the former form, I cannot use directly “root /A;” in if ().
Please read If is Evil… when used in location context | NGINX.
In the latter form, I cannot use for A.org and B.org listen 1.1.1.1, as
Nginx says it cannot bind twice IP1.1.1.1 (it can bind to it for A, but
since the socket is already occupied, it cannot bind for for B.org}.
The assertion that you cannot use the same IP twice is wrong, and
probably the root of your misunderstanding. This is legitimate
configuration:
http {
server {
listen 1.1.1.1:80;
server_name A.org;
root /srv/A.org/public;
}
server {
listen 1.1.1.1:80;
server_name B.org;
root /srv/B.org/public;
}
server {
listen 1.1.1.2:80;
server_name C.org;
root /srv/C.org/public;
}
}
There are more concise ways of expressing this setup, especially if
you’re dealing with significant numbers of domains, but this is pretty
unambiguous.
Jonathan
Jonathan M.
Oxford, London, UK
http://www.jpluscplusm.com/contact.html
On Sat, Apr 14, 2012 at 01:44:58PM +0200, wrote:
server_name A.org B.org;
server { server_name C.org; listen 1.1.1.2; }
In the former form, I cannot use directly “root /A;” in if ().
In the latter form, I cannot use for A.org and B.org listen 1.1.1.1, as
Nginx says it cannot bind twice IP1.1.1.1 (it can bind to it for A, but
since the socket is already occupied, it cannot bind for for B.org}.
server { listen 1.1.1.1; server_name A.org; }
server { listen 1.1.1.1; server_name B.org; }
server { listen 1.1.1.2; server_name C.org; }
Moreover, as the Nginx module documentation is available both trough
wiki.nginx.org (wiki.nginx.org/HttpCoreModule) and
nginx documentation, I would like to ask which is the
reference documentation (and what is the point to have the documentation
on two different places – e.g. why isn’t the wiki enough).
The right place is nginx documentation
Until this year the only English documentation was in wiki,
but the wiki contains errors and inaccurancies.
–
Igor S.