Centos7源码编译安装Nginx1.13的方法

发布时间:2021-05-31 11:40:05 作者:小新
来源:亿速云 阅读:129

这篇文章给大家分享的是有关Centos7源码编译安装Nginx1.13的方法的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

关于nginx的相关介绍我就不说了,既然你选择nginx作为你的web服务器,想必你多少也对nginx server有不同认知和理解,接下来我就直接安装。

1.先决条件:

我使用的是centos7.3 64位核心版系统,安装配置nginx前必须安装nginx依赖包,请查看;Centos 7编译安装php7.1之生产篇,并安装前文开头所提供的依赖包。此依赖组件包适用于Nginx任意版本。

新建web用户和组

$ /usr/sbin/groupadd www
$ /usr/sbin/useradd -g www www
$ ulimit -SHn 65535 //设置linux高负载参数

2.从官方下载Nginx以及OpenSSL

下载Nginx时有两个版本:开发版和稳定版,如果用于生产就下载稳定版本,http://nginx.org/en/download.html (最好下载最新版本的稳定版,这样会有bug修复以及新特性)我下载的是就是目前最新版本nginx-1.13.5。

$ cd /tmp
$ wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz
$ tar zxvf openssl-1.1.0e.tar.gz
$ wget https://nginx.org/download/nginx-1.13.5.tar.gz
$ tar zxvf nginx-1.13.5.tar.gz
$ 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程序呢,别慌,下一篇文章中我会写到。

感谢各位的阅读!关于“Centos7源码编译安装Nginx1.13的方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. CentOS7中源码编译安装LAMP架构
  2. centos7下源码编译安装mysql 5.7.21的简单教程

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

centos7 nginx1.13

上一篇:CentOS7中怎么安装Tomcat 9

下一篇:centos7 PHP环境如何搭建GD库等插件

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》