基于ip
vi /etc/nginx/nginx.conf
server {
listen 192.168.1.142:80;
server_name localhost;
access_log logs/host.access.log main;
location / {
root /web2;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 192.168.1.143:80;
server_name localhost;
location / {
root /web3;
index index.html index.htm index.php;
}
}
测试
*********************************************************************
基于端口
vi /etc/nginx/nginx.conf
server {
listen 192.168.1.142:80;
server_name localhost;
access_log logs/host.access.log main;
location / {
root /web2;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 192.168.1.142:81;
server_name localhost;
location / {
root /web3;
index index.html index.htm index.php;
}
}
****************************************************************************************
基于域名
vi /etc/nginx/nginx.conf
server {
listen 192.168.1.142:80;
server_name www.lei.com;
access_log logs/host.access.log main;
location / {
root /web2;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 192.168.1.142:80;
server_name www.han.com;
location / {
root /web3;
index index.html index.htm index.php;
}
}
*******************************************************************************************
访问控制
vi /etc/nginx/nginx.conf
在location / {中添加
auth_basic "mima";
auth_basic_user_file /usr/local/nginx/conf/.passwd.db;
生成密码
htpasswd -cm /usr/local/nginx/conf/.passwd.db aaa
*****************************************************************************************
虚拟目录
vi /etc/nginx/nginx.conf
在server中写
location /aaa {
alias /web3/;
}
重启
测试