Monday, 15 September 2014

nginx multiple subdomains with their own config -



nginx multiple subdomains with their own config -

nginx web server runs on ubuutu server. have multiple websites under /var/www. let's maintain simple (myipaddres/web1 & myipaddres/web2)

/var/www/web1 /var/www/web2

at moment nginx confg (single file) looks (root points /var/www)

server { hear 80 default_server; hear [::]:80 default_server ipv6only=on; server_name localhost; root /var/www; index index.php index.html index.htm; }

but want have unique nginx configuration each subdomain (myipaddres/web1 & myipaddres/web2) like

/etc/nginx/sites-available/web1 & /etc/nginx/sites-available/web2

i trying this, nginx fails reload.

/etc/nginx/sites-available/web1

looks this

server { hear 80 default_server; hear [::]:80 default_server ipv6only=on; server_name localhost; root /var/www/web1; index index.php index.html index.htm; } /etc/nginx/sites-available/web2

looks this

server { hear 80 default_server; hear [::]:80 default_server ipv6only=on; server_name localhost; root /var/www/web2; index index.php index.html index.htm; }

each server must have unique pair server_name , listen $port.

so have 2 variants:

change server_name localhost2 , add together 127.0.0.1 localhost /etc/hosts . (bad variant) use location

server { hear 80 default_server; hear [::]:80 default_server ipv6only=on; server_name localhost; index index.php index.html index.htm; location /web1 { root /var/www; } location /web2 { root /var/www; } }

or if want has different file each app:

server { hear 80 default_server; hear [::]:80 default_server ipv6only=on; server_name localhost; index index.php index.html index.htm; include locations/app*.conf; }

and 2 file: /etc/nginx/locations/app1.conf , /etc/nginx/locations/app2.conf text

location /web1 { root /var/www; }

and

location /web2 { root /var/www; }

nginx

No comments:

Post a Comment