Nginx虛擬主機配置

1. 基於ip的虛擬主機配置

假設Nginx服務同時配置了192.168.25.100/141兩個IPhtml

server {
    listen       80;
    server_name  192.168.25.141;

    location / {
        root   /usr/share/nginx/html/html-141;
        index  index.html index.htm;
    } 
}

server {
    listen       80;
    server_name  192.168.25.100;

    location / {
        root   /usr/share/nginx/html/html-100;
        index  index.html index.htm;
    } 
}

 

2. 基於端口的虛擬主機配置

server {
    listen       81;
    server_name  192.168.25.141;

    location / {
        root   html-81;
        index  index.html index.htm;
}

server {
    listen       82;
    server_name  192.168.25.141;

    location / {
        root   html-82;
        index  index.html index.htm;
}

 

3. 基於域名的虛擬主機配置

server {
    listen       80;
    server_name  www.itma.com;

    location / {
        root   html-www;
        index  index.html index.htm;
}

server {
    listen       80;
    server_name  hehe.itma.com;

    location / {
        root   html-hehe;
        index  index.html index.htm;
}
相關文章
相關標籤/搜索