源码包安装 Nginx 配置过程

修改版本V1.1。

一.Nginx 配置过程

1.下载nginx源码包

[root@localhost 1]# wget -c http://nginx.org/download/nginx-1.14.0.tar.gz
-bash: wget: 未找到命令   #缺少wget命令
[root@localhost 1]# yum install wget -y   #wget安装完毕继续执行以下命令
[root@localhost 1]# wget -c http://nginx.org/download/nginx-1.14.0.tar.gz
--2019-08-19 19:50:13--  http://nginx.org/download/nginx-1.14.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
正在连接 nginx.org (nginx.org)|62.210.92.35|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:http://117.128.6.11/cache/nginx.org/download/nginx-1.14.0.tar.gz?ich_args2=471-19195416057907_c68489af48a342d4d96e3d5442d9961a_10001002_9c89622ad5c2f4d79e3f518939a83798_dce717bbf01ac9d1291c27e56e2c7bd4 [跟随至新的 URL]
--2019-08-19 19:50:15--  http://117.128.6.11/cache/nginx.org/download/nginx-1.14.0.tar.gz?ich_args2=471-19195416057907_c68489af48a342d4d96e3d5442d9961a_10001002_9c89622ad5c2f4d79e3f518939a83798_dce717bbf01ac9d1291c27e56e2c7bd4
正在连接 117.128.6.11:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1016272 (992K) [application/octet-stream]
正在保存至: “nginx-1.14.0.tar.gz”

100%[========================================>] 1,016,272   2.34MB/s 用时 0.4s   

2019-08-19 19:50:15 (2.34 MB/s) - 已保存 “nginx-1.14.0.tar.gz” [1016272/1016272])

[root@localhost 1]# ls
nginx-1.14.0.tar.gz

2.解压nginx源码包

[root@localhost 1]# tar -zxf nginx-1.14.0.tar.gz
[root@localhost 1]# ls
nginx-1.14.0  nginx-1.14.0.tar.gz

3.安装C编译器

[root@localhost 1]# cd nginx-1.14.0
[root@localhost nginx-1.14.0]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README
[root@localhost nginx-1.14.0]# yum install gcc -y

4.预编译configure

[root@localhost nginx-1.14.0]# ./configure 
--prefix=/data/nginx 
--with-http_stub_status_module 
--with-http_ssl_module

5.编译出错

./configure: error: the HTTP rewrite module requires the PCRE library.
#./configure: error: HTTP重写模块需要PCRE库。
You can either disable the module by using --without-http_rewrite_module
#您可以使用——with -http_rewrite_module禁用模块
option, or install the PCRE library into the system, or build the PCRE library
#选项,或将PCRE库安装到系统中,或构建PCRE库
statically from the source with nginx by using --with-pcre=<path> option.
#通过使用——with-pcre=<path>选项静态地从nginx源文件中获取。

6.根据提示安装PCRE库

[root@localhost nginx-1.14.0]# yum install pcre-devel -y   #安装PCRE库后继续预编译
[root@localhost nginx-1.14.0]# ./configure 
--prefix=/data/nginx 
--with-http_stub_status_module 
--with-http_ssl_module
#安装PCRE库后依然提示编译出错
./configure: error: SSL modules require the OpenSSL library.
#./configure: error: SSL模块需要OpenSSL库。
You can either do not enable the modules, or install the OpenSSL library
#您可以不启用模块,或者安装OpenSSL库
into the system, or build the OpenSSL library statically from the source
#或者从源代码静态地构建OpenSSL库
with nginx by using --with-openssl=<path> option.
#使用——with-openssl=<path>选项。

7.根据提示安装OpenSSL库

[root@localhost nginx-1.14.0]# yum install openssl-devel -y   #安装OpenSSL库后继续预编译
[root@localhost nginx-1.14.0]# ./configure 
--prefix=/data/nginx 
--with-http_stub_status_module 
--with-http_ssl_module

8.预编译完成

Configuration summary
 - using system PCRE library
 - using system OpenSSL library
 - using system zlib library

  nginx path prefix: "/data/nginx"
  nginx binary file: "/data/nginx/sbin/nginx"
  nginx modules path: "/data/nginx/modules"
  nginx configuration prefix: "/data/nginx/conf"
  nginx configuration file: "/data/nginx/conf/nginx.conf"
  nginx pid file: "/data/nginx/logs/nginx.pid"
  nginx error log file: "/data/nginx/logs/error.log"
  nginx http access log file: "/data/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

9.进行编译与编译安装

[root@localhost nginx-1.14.0]# make && make install

10.检查检查 nginx 配置文件是否正确

[root@localhost nginx-1.14.0]# /data/nginx/sbin/nginx -t
nginx: the configuration file /data/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx/conf/nginx.conf test is successful

11.启动nginx

[root@localhost nginx-1.14.0]# /data/nginx/sbin/nginx
[root@localhost nginx-1.14.0]# ps -ef | grep nginx   #查看nginx是否启动
root      12444      1  0 21:24 ?        00:00:00 nginx: master process /data/nginx/sbin/nginx
nobody    12445  12444  0 21:24 ?        00:00:00 nginx: worker process
root      12447   7199  0 21:24 pts/0    00:00:00 grep --color=auto nginx

12.通过浏览器访问 Nginx 默认测试页面
访问Nginx测试页面
13.检查防火墙是否关闭,与关闭

[root@localhost nginx-1.14.0]# firewall-cmd --state
running
[root@localhost nginx-1.14.0]# systemctl stop firewalld.service
[root@localhost nginx-1.14.0]# firewall-cmd --state
not running

14.继续通过浏览器访问 Nginx 默认测试页面
访问Nginx测试页面
访问成功,成功安装Nginx。

二.利用系统脚本自动启动Nginx

1.设置流程方法

[root@localhost ~]# vim /etc/rc.d/rc.local   #编辑开机启动脚本
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
systemctl stop firewalld.service   #关闭防火墙
/usr/local/nginx/sbin/nginx   #启动nginx
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
~                                                                                 
-- 插入 --                                                      15,28        全部
[root@localhost ~]# cd /etc/rc.d
[root@localhost rc.d]# chmod +x /etc/rc.d/rc.local
[root@localhost rc.d]# ll rc.local -d
-rwxr-xr-x. 1 root root 534 8月  23 18:27 rc.local
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值