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
安装成功截图
2. 配置基于域名的虚拟主机。
mkdir conf.d
vim nginx.conf
systemctl restart nginx
配置虚拟主机
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
3、 配置nginx基于用户和地址的访问控制。
vim conf.d/vhost.conf
systemctl restart nginx
基于用户访问
vim conf.d/vhost.conf
systemctl restart nginx
安装认证工具
yum install httpd-tools
htpasswd -c -m /data/web1/webpass tom
4、 配置nginx rewrite,要求如果访问不存在的任意网页都重定向到错误页面,错误页面内容自行定义
echo "web not exist" >/data/web1/err.html
vim conf.d/vhost.conf