目录
六、配置nginx rewrite,要求如果访问不存在的任意网页都重定向到错误页面,错误页面内容自行定义
一、 源码安装nginx,并提供服务脚本
1、下载nginx源码包
curl -o nginx-1.20.1.tar.gz http://nginx.org/download/nginx-1.20.1.tar.gz
2、添加nginx用户
useradd nginx -c "Nginx web server" -d /var/lib/nginx -s /sbin/nologin -r
id nginx
3、编译安装
将安装包解压到安装目录
tar xf nginx-1.20.1.tar.gz -C /usr/local/src
cd /usr/local/src/nginx-1.20.1/
添加需要编译的参数和模块
./configure --user=nginx --group=nginx \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_auth_request_module \
--with-http_gzip_static_module \
--with-http_gunzip_module \
--with-http_stub_status_module
#
./configure: error: C compiler cc is not found
没有C语言的编译环境
#
yum install -y gcc gcc-c++
继续
#
./configure: error: the HTTP rewrite module requires the PCRE library.
报错缺失一个pcre库
#
yum install pcre-devel -y
继续
#
./configure: error: SSL modules require the OpenSSL library.
缺失一个openssl库
#
yum install openssl-devel -y
继续
出现汇总信息
编译
make
安装
make install
编译配置文件
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# ExecStartPre ExecStart
后面的第一个路径改为汇总信息的里nginx binary file: 的路径
第二个路径改为你指定的目录(--prefix=)里面的conf/nginx.conf路径
重新加载daemon-reload守护进程
systemctl daemon-reload
设置开机自启
systeml enable --now nginx
启动nginx
systemctl start nginx
查看端口
netstat -lntup | grep 80