centos 7 下 nginx 1.10.3 编译安装的方法
安装所需环境
Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境。
一. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:
yum install gcc-c++
二. PCRE pcre-devel 安装
PCRE(Perl Compatible
Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre
来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre
开发的一个二次开发库。nginx也需要此库。命令:
yum install -y pcre pcre-devel
三. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。
yum install -y zlib zlib-devel
四. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。
yum install -y openssl openssl-devel
官网下载
1.直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html

2.使用wget命令下载(推荐)。
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz

我下载的是1.10.1版本,这个是目前的稳定版。
解压
依然是直接命令:
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
配置
其实在 nginx-1.10.1 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。
1.使用默认配置
./configure
2.自定义配置(不推荐)
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录
编译安装
make
make install
查找安装路径:
whereis nginx

启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
查询nginx进程:
ps aux|grep nginx
重启 nginx
1.先停止再启动(推荐):
对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:
./nginx -s quit
./nginx
2.重新加载配置文件:
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload
启动成功后,在浏览器可以看到这样的页面:

开机自启动
即在rc.local增加启动代码就可以了。
vi /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx
设置执行权限:
chmod 755 rc.local

到这里,nginx就安装完毕了,启动、停止、重启操作也都完成了,当然,你也可以添加为系统服务,我这里就不在演示了。
启动报错处理 :
启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
启动时报80端口被占用:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

解决办法:1、安装net-tool 包:yum install net-tools
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
查询nginx进程:
ps aux|grep nginx
重启 nginx
1.先停止再启动(推荐):
对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:
./nginx -s quit
./nginx
2.重新加载配置文件:
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload
启动成功后,在浏览器可以看到这样的页面:

nginx 下安装 php 设置 属性
安装php
yum install php php-mysql php-fpm
安装过程中经常会见到如下问题:
2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit)
解决方法:
把php-mysql换成php-mysqlnd
即执行yum install php php-mysqlnd php-fpm
配置php处理器
vim /etc/php.ini
查找cgi.fix_pathinfo
将 ;cgi.fix_pathinfo=1改为cgi.fix_pathinfo=0配置www.conf
vim /etc/php-fpm.d/www.conf
将
user = nobody
group = nobody
改为
user = nginx
group = nginx
前提是已经创建了nginx用户和nginx组。 //这里可以不改 也可以执行d起动php-fpm
systemctl start php-fpm
设置php-fpm开机启动
systemctl enable php-fpm
配置nginx
打开/etc/nginx/conf.d/default.conf,如果不存在则创建
粘贴
server {
listen 80;
server_name server_domain_name_or_IP; (例如192.168.201.235)note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}location ~ .php$ {
try_files $uri =404;
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
}- 然在 /usr/local/nginx/conf/nginx.conf 将上述文件include 到http 标签中即可 inculde ../conf.d/*.conf
重起nginx
systemctl restart nginx
测试php
创建/usr/share/nginx/html/index.php/usr/share/nginx/html/info.php
centos 7 下 nginx 1.10.3 编译安装的方法的更多相关文章
- CentOS 7.2使用源码包编译安装MySQL 5.7.22及一些操作
CentOS 7.2使用源码包编译安装MySQL 5.7.22及一些操作 2018年07月05日 00:28:38 String峰峰 阅读数:2614 使用yum安装的MySQL一般版本比较旧,但 ...
- 新安装和已安装nginx如何添加未编译安装模块/补丁
新安装和已安装nginx如何添加未编译安装模块/补丁 --http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=10485& ...
- RHEL6下获取安装包(RPM)而不安装的方法
RHEL6下获取安装包(RPM)而不安装的方法 有时候我们只能在某个机器上网获得RPM安装包,如何将RPM包在不能上网的内网机器安装,就需要能将安装包下载到本地而不安装,然后再把这些包复制到内网机器, ...
- centOS linux 下nginx编译安装详解
Nginx的官方网站是 www.nginx.org Nginx的下载地址是:http://nginx.org/en/download.html 由 于官网的设计非常简洁不大气不上档次,所以我们 ...
- centos 7 下nginx启动脚本
centos 7下用了版本6下的脚本,总是报错,于是拷贝了nginx一键安装包里面的一个版本,结果可以,贴出来 #! /bin/sh # chkconfig: # Description: Start ...
- Nginx 1.10.1 编译、配置文档(支持http_v2,TLSv1.2,openssl v1.0.2)
1.安装常用工具及基础包: [root@localhost /]# yum -y install wget git vim make gcc gcc-c++ openssl-devel [root@l ...
- CentOS下MySQL 5.7.9编译安装
MySQL 5.7 GA版本的发布,也就是说从现在开始5.7已经可以在生产环境中使用,有任何问题官方都将立刻修复. MySQL 5.7主要特性: 更好的性能:对于多核CPU.固态硬盘.锁有着更好的优化 ...
- Centos下Sphinx的下载与编译安装
官方下载地址 http://sphinxsearch.com/downloads/release/ 百度云下载地址 https://pan.baidu.com/s/1gfmPbd5 wget ...
- centos 7下nginx搭建流媒体服务器【动态添加模块】
1.安装nginx依赖包 yum install gcc gcc-c++ openssl-devel zlib-devel pcre pcre-devel yamdi 2.下载解压nginx_mod_ ...
随机推荐
- SpringBoot HttpServletResponse Header Cookie输出问题
问题: 在一次Response写入header和cookie的时候,发现部分信息没有被输出 工具类: CookieUtils: import java.io.IOException; import j ...
- python 基础知识点一
基础数据类型初始. 数字:int 12,3,45 + - * / ** int: bit_lenth()转化为2进制的最小位数. % 取余数 ps:type() 字符串转化成数字:int(str ...
- DDD 之 Multiple Canonical Models
MultipleCanonicalModels Scratch any large enterprise and you'll usually find some kind of group focu ...
- malloc/free 和 new/delete
(本文参考于网上) 首先两者都可用于申请动态内存和释放内存。 对于非内部数据类型的对象而言,只用malloc/free无法满足动态对象的要求.对象在创建的同时要自动执行构造函数,对象在消亡之前要自动执 ...
- Qt基础学习---滑动条之QSlider
Qt滑动条基本用法: //mydialog.h #ifndef MYDIALOG_H #define MYDIALOG_H #include <QDialog> class QLineEd ...
- nginx windows版 下载和启动
nginx Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.因它的稳定性.丰富的功能集.示例配置文件和低系统资源的消耗而闻名.在连 ...
- echarts4的学习
echarts的学习 1.echarts的全解注释.https://www.2cto.com/kf/201708/665624.html ### 2.从echarts3开始学习echarts源码.ht ...
- caffe arm
依赖库: sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-de ...
- Andorid Studio中运行模拟器--夜神模拟器
这样可以直接在夜神模拟器上运行app然后在androidstudio上查看log…. 1.下载夜神模拟器 2.修改配置 点击右上角的设置图标,对夜神模拟器的分辨率进行选择,手机版的480×800的就差 ...
- js 里面的那些节省字节的写法 a|0 void 0等等
//取整 parseInt(a,10); Math.floor(a); ~~a; //节省之后的写法 a|0; //节省之后的写法 //四舍五入 Math.round(a); a+.5|0; //节省 ...