nginx安装
nginx简单安装
#!/bin/bash
yum -y install nginx
systemctl enable nginx
systemctl restart nginx
firewall-cmd --add-port=80/tcp
firewall-cmd --add-port=80/tcp --permanent
nginx虚拟网站
根据端口区分
[root@S2 html]# mkdir -p /sy/1
[root@S2 html]# mkdir -p /sy/2
[root@S2 html]# echo "1" > /sy/1/index.html
[root@S2 html]# echo "2" > /sy/2/index.html
[root@S2 conf.d]# vim /etc/nginx/conf.d/sy.conf
server {
listen 81;
server_name 1.com;
location / {
root /sy/1 ;
}
}
server {
listen 82;
server_name 2.com;
location / {
root /sy/2 ;
}
}
[root@S2 conf.d]# firewall-cmd --add-port=81/tcp
success
[root@S2 conf.d]# firewall-cmd --add-port=82/tcp
success
[root@S2 conf.d]# firewall-cmd --add-port=81/tcp --permanent
success
[root@S2 conf.d]# firewall-cmd --add-port=82/tcp --permanent
success
[root@S2 conf.d]# systemctl restart nginx
根据域名区分
[root@S2 html]# mkdir -p /sy/1
[root@S2 html]# mkdir -p /sy/2
[root@S2 html]# echo "1" > /sy/1/index.html
[root@S2 html]# echo "2" > /sy/2/index.html
[root@S2 conf.d]# vim /etc/nginx/conf.d/sy.conf
server {
listen 80;
server_name 1.com;
location / {
root /sy/1 ;
}
}
server {
listen 80;
server_name 2.com;
location / {
root /sy/2 ;
}
}
[root@S2 conf.d]# echo "192.168.59.102 1.com" >> /etc/hosts
[root@S2 conf.d]# echo "192.168.59.102 2.com" >> /etc/hosts
[root@S2 conf.d]# firewall-cmd --add-port=80/tcp
success
[root@S2 conf.d]# firewall-cmd --add-port=80/tcp --permanent
success
[root@S2 conf.d]# systemctl restart nginx
注意
nginx默认
autoindex off;
nginx默认不能打开目录,之前用nginx配置yum本地仓库的时候出现过这个问题,访问nginx的/usr.share/nginx/html/下的目录时会报403的错,最后发现是因为这个,把off改成on就完事。
计算机英语
location | 位置 |
server | 服务器 |