资讯专栏INFORMATION COLUMN

CentOs7.3 编译安装 Nginx 1.9.9

endiat / 2457人阅读

摘要:默认情况下,该模块没有被构建。使用时,需要从网站下载库的源码版本并解压,剩下的就交给的和来完成。正则表达式使用在指令和模块中。在默认就启用的网络传输压缩模块时需要使用。

CentOs7.3 编译安装 Nginx 1.9.9 安装 安装依赖
$ yum install -y  gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
下载并解压
$ cd /opt/
$ wget http://nginx.org/download/nginx-1.9.9.tar.gz
$ tar zxvf nginx-1.9.9.tar.gz
编译

编译时候可以指定编译参数,参考文章尾部:常用编译选项

$ cd nginx-1.9.9
$ ./configure 
安装
$ make
$ make && make install

默认安装在/usr/local/nginx

里面有四个目录:

conf: 配置文件夹,最重要文件是nginx.conf

html: 静态网页文件夹

logs: 日志文件夹

sbin: nginx 的可执行文件,启动、停止等操作

常用命令 正确性检查

每次修改nginx配置文件后都要进行检查

$ /usr/local/nginx/sbin/nginx -t
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动
$ /usr/local/nginx/sbin/nginx

如果不能访问,检查防火墙并关闭防火墙

centos 6.x 关闭 iptables

$ service iptables status # 查询防火墙状态命令
$ service iptables stop # 关闭命令

centos 7.x 关闭firewall

$ ssystemctl status  firewalld.service # 查看状态
$ systemctl stop firewalld.service # 停止firewall

浏览器输入本机IP ,看到如下内容证明安装成功

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.
停止
$ /usr/local/nginx/sbin/nginx -s stop
重启
$ /usr/local/nginx/sbin/nginx -s reload
常用编译选项
./configure 
--prefix=/home/nginx 
--sbin-path=/usr/sbin/nginx 
--user=nginx 
--group=nginx 
--conf-path=/etc/nginx/nginx.conf 
--error-log-path=/home/log/nginx/error.log 
--http-log-path=/home/log/nginx/access.log 
--with-http_ssl_module 
--with-http_gzip_static_module 
--with-http_stub_status_module 
--with-http_realip_module 
--pid-path=/home/run/nginx.pid 
--with-pcre=/home/software/pcre-8.35 
--with-zlib=/home/software/zlib-1.2.8 
--with-openssl=/home/software/openssl-1.0.1i
选项说明
--prefix=/home/nginx  Nginx安装的根路径,所有其它路径都要依赖该选项
--sbin-path=/usr/sbin/nginx  nginx的可执行文件的路径(nginx)
--user=nginx  worker进程运行的用户
--group=nginx  worker进程运行的组
--conf-path=/etc/nginx/nginx.conf   指向配置文件(nginx.conf)
--error-log-path=/var/log/nginx/error.log  指向错误日志目录
--http-log-path=/var/log/nginx/access.log   设置主请求的HTTP服务器的日志文件的名称
--with-http_ssl_module   使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
--with-http_gzip_static_module   启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
--with-http_stub_status_module   启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
--with-http_realip_module   启用ngx_http_realip_module支持(这个模块允许从请求标头更改客户端的IP地址值,默认为关)
--pid-path=/var/run/nginx.pid   指向pid文件(nginx.pid)

设置PCRE库的源码路径,如果已通过yum方式安装,使用–with-pcre自动找到库文件。使用–with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 – 8.30)并解压,剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
--with-pcre=/home/software/pcre-8.35  

指定 zlib(版本1.1.3 – 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
--with-zlib=/home/software/zlib-1.2.8 

指向openssl安装目录
--with-openssl=/home/software/openssl-1.0.1i
Contact

作者:鹏磊

出处:http://www.ymq.io

Email:admin@souyunku.com

版权归作者所有,转载请注明出处

Wechat:关注公众号,搜云库,专注于开发技术的研究与知识分享

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/40551.html

相关文章

  • Ubuntu 17.04 编译安装 Nginx 1.9.9 配置 https 免费证书

    摘要:编译安装配置免费证书安装安装依赖下载并解压编译安装默认安装在里面有四个目录配置文件夹,最重要文件是静态网页文件夹日志文件夹的可执行文件,启动停止等操作常用命令正确性检查每次修改配置文件后都要进行检查启动浏览 Ubuntu 17.04 编译安装 Nginx 1.9.9 配置 https 免费证书 安装 Nginx 安装依赖 $ apt-get update $ apt-get insta...

    sevi_stuo 评论0 收藏0
  • 虚拟机上Centos7开发环境搭建(编译安装LNMP,多版本PHP共存,PHP扩展安装

    摘要:安装系统本次安装的是的最小化版本,以下操作在用户下进行。在搭建完该环境后,笔者使用作为开发,配置使其可以直接调试虚拟机上的代码即开发环境下代码是运行在虚拟机上的。通过该方法,可以最大程度地确保开发环境与生产环境的一致性。 安装系统 本次安装的是Centos7.3的最小化版本,以下操作在root用户下进行。在搭建完该环境后,笔者使用phpstorm作为开发ide,配置phpstorm使其...

    zhangke3016 评论0 收藏0
  • CentOS7.3 安装配置 Nginx、MariaDB、PHP

    摘要:编译提示如下成功离开目录检查是否安装成功执行如下命令启动,并用命令检查启动情况添加到系统服务增加如下内容结合安装时的配置文件进行修改其中特殊的环境变量可用于表示主进程的。以下组件也可以挑需要的安装。成功后删除测试页面。 CentOS7.3 安装配置 Nginx、MariaDB、PHP 配置 nginx 安装参数并安装 配置 以下参数也可以在后期通过配置 conf 文件进行配置基本配置如...

    tommego 评论0 收藏0

发表评论

0条评论

endiat

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<