CentOS7源码安装Nginx1.22

CentOS7源码安装Nginx1.22


下载源码包:

[root@localhost ~]# wget http://nginx.org/download/nginx-1.22.1.tar.gz

安装依赖:

[root@localhost ~]# yum -y install gcc make pcre pcre-devel openssl openssl-devel zlib zlib-devel GeoIP-devel.x86_64  gd gd-devel.x86_64

创建nginx用户:

[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -g nginx -s /sbin/nologin nginx

解压安装源码包:

[root@localhost ~]# tar -xvf nginx-1.22.1.tar.gz -C /usr/local/

编译nginx:

[root@localhost ~]# cd /usr/local/nginx-1.22.1/
[root@localhost nginx-1.22.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-threads --with-stream --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module
[root@localhost nginx-1.22.1]# make && make install 

详细编译参数:可以参考官网 http://nginx.org/en/docs/configure.html

[root@localhost nginx-1.22.1]# ./configure  \
--prefix=/usr/local/nginx  \
--user=nginx  \
--group=nginx  \
--with-threads  \
--with-stream \
--with-file-aio \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_image_filter_module \ --with-http_geoip_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_auth_request_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_stub_status_module \

查看nginx版本:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.22.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-http_realip_module --with-http_geoip_module --with-http_sub_module

使用system管理:


[root@localhost ~]# vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

配置nginx环境变量:

[root@localhost ~]# vim /etc/profile
export PATH=$PATH:/usr/local/nginx/sbin

[root@localhost ~]# source /etc/profile

启动nginx:

[root@localhost ~]# systemctl enable --now nginx

 

posted @ 2022-11-26 17:52  Noleaf  阅读(489)  评论(0编辑  收藏  举报