Bootstrap

Nginx 配置基于主机名的 Web 服务器

配置方法如下
1.启动nginx

nginx 
systemctl start nginx

2.关闭权限

cd  /usr/share/nginx/html/
setenforce 0

3.添加自己的ip
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4
localhost4.localdomain4
::1 localhost localhost.localdomain localhost6
localhost6.localdomain6

192.168.232.130   www.example.com
192.168.232.130   www.example.net

注意:添加的是自己的ip
4.

cd /etc/nginx/conf.d
vim com.conf
server{
server_name www.example.com;
root /var/www/example.com/;
access_log /var/log/www/example.com/access.log;
error_log /var/log/www/example.com/error.log;
}
vim net.conf
server{
server_name www.example.net;
root /var/www/example.net/;
access_log  /var/log/www/example.net/access.log;
error_log  /var/log/www/example.net/error.log;
}
mkdir -p /var/www/example.com/
mkdir -p /var/www/wxample.net/
echo example.com  > /var/www/example.com/index.html
mkdir /var/log/nginx/example.net
mkdir /var/nginx/example.com
echo example.net > /var/www/example.net/index.html

6.查看效果

[root@localhost conf.d]# curl www.example.com
example.com
[root@localhost conf.d]# curl www.example.net
example.net
;