详解Centos7源码编译安装Nginx1.13
关于nginx的相关介绍我就不说了,既然你选择nginx作为你的web服务器,想必你多少也对nginx server有不同认知和理解,接下来我就直接安装。
1.先决条件:
我使⽤的是centos7.3 64位核⼼版系统,安装配置nginx前必须安装nginx依赖包,请查看;,并安装前⽂开头所提供的依赖包。此依赖组件包适⽤于Nginx任意版本。
新建web⽤户和组
$ /usr/sbin/groupadd www
$ /usr/sbin/useradd -g www www
$ ulimit -SHn 65535 //设置linux⾼负载参数
2.从官⽅下载Nginx以及OpenSSL
$ cd /tmp
$ wget /source/openssl-1.1.
$ tar zxvf openssl-1.1.
$ wget /download/nginx-1.13.
$ tar zxvf nginx-1.13.
centos7没有vim命令$ cd nginx-1.13.5
3.安装Nginx
你可能会注意到有些⽂档教程安装nginx的时候,并未指派这么多模块,(看起来好长),有的连模块和⽤户都没有指派,其实模块是根据⾃⼰的需要指派的,如果想以后不⿇烦,那么就按照下⾯的模块指派就⾏了,其实这也算是全能的了,不然后期你需要什么还得重新编译进去,不是很⿇烦,但也不省事。⾄于是否指派⽤户组,我坚决会让你指派,这可关乎nginx配置的可⽤性和安全稳定。
$ ./configure \
--prefix=/usr/local/nginx \
-
-user=www \
--group=www \
--with-pcre \
--with-openssl=/tmp/openssl-1.1.0e \
--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 -j8 && make install //编译并安装
4.创建 systemctl 系统 Nginx 单元⽂件
安装完成后还需要开机⾃启动,不然每次开机都需要⼿动,那岂不是太⿇烦。
$ vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP /usr/local/nginx/logs/nginx.pid
ExecStop=/bin/kill -s QUIT /usr/local/nginx/logs/nginx.pid
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存并退出。
5.加⼊开机⾃启动并启动Nginx
$ systemctl enable nginx.service
$ systemctl restart nginx.service
6.设置Firewalld防⽕墙
$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ firewall-cmd --reload
7.查看Nginx是否启动成功
$ ss -ntlp
可以查看到nginx进程已经运⾏了。到此nginx安装就完成了,可能你还会有疑问,nginx怎么解析并⽀持php程序呢,别慌,下⼀篇⽂章中我会写到。
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。