nginx

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服务器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值