阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

原创:Centos 7 源码编译安装 Nginx 1.13

28次阅读
没有评论

共计 2297 个字符,预计需要花费 6 分钟才能阅读完成。

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

原创:Centos 7 源码编译安装 Nginx 1.13

先决条件

我使用的是 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 高负载参数 
从官方下载 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
安装 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 // 编译并安装 
创建 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
保存并退出。
加入开机自启动并启动 Nginx
$ systemctl enable nginx.service
$ systemctl restart nginx.service
设置 Firewalld 防火墙
$ firewall-cmd --zone=public --add-port=80/tcp --permanent
$ firewall-cmd --reload
查看 Nginx 是否启动成功
$ ss -ntlp

可以查看到 nginx 进程已经运行了。到此 nginx 安装就完成了,可能你还会有疑问,nginx 怎么解析并支持 php 程序呢,别慌,下一篇文章中我会写到。

阿里云 2 核 2G 服务器 3M 带宽 61 元 1 年,有高配

腾讯云新客低至 82 元 / 年,老客户 99 元 / 年

代金券:在阿里云专用满减优惠券

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2024-07-24发表,共计2297字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中