编译安装Nginx
一、编译安装Nginx
1、关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
2、安装编译环境
yum -y install gcc gcc-c++
yum install -y pcre pcre-devel ##安装pcre软件包(使Nginx支持http rewrite模块)
yum install -y openssl-devel ##安装openssl-devel(使Nginx支持ssl)
yum install -y zlib zlib-devel gd gd-devel ##安装zlib
3、创建用户
useradd -s /sbin/nologin nginx
4、下载Nginx安装包并解压进入安装目录
wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar -zxvf nginx-1.24.0.tar.gz
cd nginx-1.24.0
5、编译配置
./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module
make && make install
cd /usr/local/nginx/sbin
6、优化路径
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
7、添加Nginx系统服务
vim /lib/systemd/system/nginx.service
将下列代码复制进去
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
8、添加执行权限并设置开机启动
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
9、浏览器访问Nginx默认IP127.0.0.1:80
显示如下页面就说明安装成功了