运维第二天

1. 源码安装nginx,并提供服务脚本。

安装nginx所需的pcre库

yum install -y pcre-devel

下载解压软件

wget -c http://nginx.org/download/nginx-1.20.0.tar.gz
tar xf nginx-1.20.0.tar.gz -C /usr/local/src/
cd /usr/local/src/nginx-1.20.0/

创建用户和组

useradd nginx -s /sbin/nologin -M

提供脚本

yum install gcc gcc-c c++ make -y
yum install pcre-devel -y
yum install openssl-devel -y
yum install perl-ExtUtils-Embed
./configure --prefix=/usr/local/nginx
 --user=nginx --group=nginx
 --with-threads
 --with-http_ssl_module  
 --with-http_sub_module
 --with-http_gzip_static_module
 --with-http_auth_request_module
 --with-http_stub_status_module
 --with-http_perl_module
 --with-stream
 --with-pcre
  
 make
 make install
安装成功截图

8a4cf0ea8dbc4ac8ad0a933008cd3241.png

 2. 配置基于域名的虚拟主机。

mkdir conf.d
vim nginx.conf
systemctl restart nginx
b8a7e16701af42aea42531cb303d7b84.png

36ccc31204ec4151b26b3bdcaacdc95e.png

 c46db1fb2c4c4e9ba56ffc69aa7884d5.png

配置虚拟主机

cd conf.d/
[root@localhost nginx]# vim vhost.conf
systemctl restart nginx
mkdir /data/web{1,2} -p
echo "web1 test" >/data/web1/index.html
echo "web2 test" >/data/web2/index.html
831f59386b2341908611b54bd2c40652.png

 3、 配置nginx基于用户和地址的访问控制。

vim conf.d/vhost.conf 
systemctl restart nginx

c13bff999fee49f891986f543df52ef7.png

 基于用户访问

vim conf.d/vhost.conf 
systemctl restart nginx
59841bac3e7143a69ea3e8d4ea531846.png

安装认证工具

yum install httpd-tools
htpasswd -c -m /data/web1/webpass tom

a8acc29f980f4b36846156eb888b9080.png

 4、 配置nginx rewrite,要求如果访问不存在的任意网页都重定向到错误页面,错误页面内容自行定义

echo "web not exist" >/data/web1/err.html
vim conf.d/vhost.conf 
11ed4ba63f874d3a92999e32a6ed9dee.png

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值