一、安装依赖包

yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel

二、下载

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.14.2.tar.gz

三、编译

tar -zxvf nginx-1.14..tar.gz
cd nginx-1.14.
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install

四、将nginx设置为服务

centos 7 中采用 systemd 来管理系统,我们为 nginx 创建服务文件

vim /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 $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

这里的 PIDFile 的配置要和前面的 配置保持一致。

设置自启动

[root@node2 logs]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

五、启动nginx

[root@node2 logs]# systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

提示报错,查看查看状态

[root@node2 logs]# systemctl status nginx
● nginx.service - The NGINX HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 二 -- :: CST; 15s ago
Process: ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=/FAILURE)
Process: ExecStartPre=/usr/local/nginx/sbin/nginx -t (code=exited, status=/SUCCESS) 4月 :: node2.jinglong nginx[]: nginx: [emerg] bind() to 0.0.0.0: failed (...e)
4月 :: node2.jinglong nginx[]: nginx: [emerg] bind() to 0.0.0.0: failed (...e)
4月 :: node2.jinglong nginx[]: nginx: [emerg] bind() to 0.0.0.0: failed (...e)
4月 :: node2.jinglong nginx[]: nginx: [emerg] bind() to 0.0.0.0: failed (...e)
4月 :: node2.jinglong nginx[]: nginx: [emerg] bind() to 0.0.0.0: failed (...e)
4月 :: node2.jinglong nginx[]: nginx: [emerg] still could not bind()
4月 :: node2.jinglong systemd[]: nginx.service: control process exited, code=e...s=
4月 :: node2.jinglong systemd[]: Failed to start The NGINX HTTP and reverse pr...er.
4月 :: node2.jinglong systemd[]: Unit nginx.service entered failed state.
4月 :: node2.jinglong systemd[]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

提示80端口被占用,此时执行:

[root@node2 sbin]# killall - nginx
-bash: killall: 未找到命令

安装killall

yum install psmisc

再执行

killall - nginx

启动服务

[root@node2 sbin]# systemctl start nginx
[root@node2 sbin]#

没有报错,查看状态

[root@node2 sbin]# systemctl status nginx
● nginx.service - The NGINX HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since 二 -- :: CST; 17s ago
Process: ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=/FAILURE)
Process: ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=/SUCCESS)
Process: ExecStartPre=/usr/local/nginx/sbin/nginx -t (code=exited, status=/SUCCESS)
Main PID: (nginx)
CGroup: /system.slice/nginx.service
├─ nginx: master process /usr/local/nginx/sbin/nginx
└─ nginx: worker process 4月 :: node2.jinglong systemd[]: Starting The NGINX HTTP and reverse proxy server...
4月 :: node2.jinglong nginx[]: nginx: the configuration file /usr/local/ngin...ok
4月 :: node2.jinglong nginx[]: nginx: configuration file /usr/local/nginx/co...ul
4月 :: node2.jinglong systemd[]: Started The NGINX HTTP and reverse proxy server.
Hint: Some lines were ellipsized, use -l to show in full.

此时为running,启动成功,执行

[root@node2 sbin]# curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>

获取页面成功

建立软连接

ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

此时nginx可以在任意目录下执行命令

centos7编译安装nginx的更多相关文章

  1. Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.3 + Mariadb 10.1.20 + Nginx 1.10.2 + PHP 7.1.0 + Laravel 5.3 )

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1611.iso 安装步骤: 1.准备 1.0 查看硬 ...

  2. CentOS7 编译安装 Nginx (实测 笔记 Centos 7.0 + nginx 1.6.2)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  3. Centos7 编译安装 Nginx Mariadb Asp.net Core2 (实测 笔记 Centos 7.3 + Openssl 1.1.0h + Mariadb 10.3.7 + Nginx 1.14.0 + Asp.net. Core 2 )

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1611.iso 安装步骤: 1.准备 1.0 查看硬 ...

  4. Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.3 + Openssl 1.1.0e + Mariadb 10.1.22 + Nginx 1.12.0 + PHP 7.1.4 + Laravel 5.4 )

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1611.iso 安装步骤: 1.准备 1.0 查看硬 ...

  5. Centos7 编译安装 Nginx、MariaDB、PHP

    前言 本文主要大致介绍CentOS 7下编译安装Nginx.MariaDB.PHP.面向有Linux基础且爱好钻研的朋友.技艺不精,疏漏再所难免,还望指正. 环境简介: 系统: CentOS 7,最小 ...

  6. Centos7 编译安装 Nginx PHP Mariadb Memcache扩展 ZendOpcache扩展 (实测 笔记 Centos 7.0 + Mariadb 10.1.9 + Nginx 1.9.9 + PHP 5.5.30)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7-x86_64-Minimal-1503-01.iso 安装步骤: 1.准备 1.1 ...

  7. centos7编译安装nginx及无缝升级https

    安装依赖: yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel 下载nginx: wget -c  ...

  8. Centos7编译安装Nginx+keepalived

    一.安装环境.主机信息及软件版本 Nginx:1.12.2keepalived:2.0.12时间同步(同步后确认各服务器时间是否一致,不一致需要修改一下时区) 关闭防火墙 二.编译安装Nginx 1. ...

  9. Centos7 编译安装Nginx 教程

    相信经过上篇博文的学习,聪明的你已经学会了如何在Centos7 上通过yum 方式安装Nginx ,但是有时候有些场景或者特俗情况下,我们往往需要通过编译源码方式安装,以便于更灵活地定制我们的Ngin ...

  10. CentOS7 编译安装Nginx+php并配置php-fpm模块

    1.编译安装PHP7.2.0 去官网下载安装包:http://php.net/downloads.php ,完成之后,上传至服务器,并释放压缩包 .tar.gz cd php- 因为我们需要编译安装, ...

随机推荐

  1. MARK DOWN 书写格式说明

    MarkdownPad2 书写格式说明: Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式,而MarkdownPad2是其中一种支持M ...

  2. 工控随笔_15_西门子_WinCC的VBS脚本_05_变量类型之三_VBS数组

    数组是一种复杂数据类型,不但有数组本身的数据类型: 数组,还有数组元素中存储的数据的类型. 一.vbs中的数组类型 在VBS中提供了两种数组类型,一种是固定数组,一种是动态数组. 1.固定数组 就是在 ...

  3. 使用SQL SERVER 来自动发送邮件

    可以使用SQL SERVER 来发送自动邮件,主要是使用SQL SERVER 的dbo.sp_send_dbmail 存储过程(在msdb数据库中). 具体步骤如下: Step1: 编写要发送的邮件内 ...

  4. C# 文字滚动特效(上下滚动)

    本程序改编至网上下载的一个自定义控件,原控件是左右滚动效果,类似于跑马灯效果,由于项目需要,改编为上下滚动. 前期没有实现自动折行,今天刚加上自动折行. using System; using Sys ...

  5. 让WebStrom支持SSH协议的子项目

    让WebStrom支持SSH协议的子项目 在大项目中, 经常会遇到子项目(submodule)使用ssh的情形, 但是WebStrom不直接支持它. 下面以MAC为例,在PC中的处理类似. 打开ter ...

  6. Android给控件添加默认点击效果

    Android控件点击效果 Android中Button控件是有点击效果的,但是像TextView.ImageView.各种Layout是没有点击效果的,给TextView设置点击事件后,加个点击效果 ...

  7. Hexo NexT主题/cnblog等博客增加点击出现红心的特效

    查看效果 每日前端 我的博客 实现:1.下载这段js代码到项目目录 ===>下载地址2.在需要的地方添加js代码 <script type="text/javascript&qu ...

  8. nodejs版 阿里云开放api签名算法

    阿里云 API 签名 github:https://github.com/liuyinglong/aliyun; npm :https://www.npmjs.com/package/aliyun-a ...

  9. chown nagios:nagios -R /var/lib/php/

    chown nagios:nagios -R /var/lib/php/

  10. HttpClient使用代理IP

    在爬取网页的时候,有的网站会有反爬虫措施,导致服务器请求拒接,可以使用代理IP来访问,解决请求拒绝的问题 代理IP分 透明代理.匿名代理.混淆代理.高匿代理 1.透明代理(Transparent Pr ...