Centos7 nginx安装--验证通过

--验证通过
 一、安装准备

首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 所以执行如下命令安装

    $   yum install gcc-c++  
    $   yum install pcre pcre-devel  
    $   yum install zlib zlib-devel  
    $   yum install openssl openssl--devel

2.安装nginx

  1.  
    $ cd /usr/local/
  2.  
    $ wget http://nginx.org/download/nginx-1.8.0.tar.gz
  3.  
    $ tar -zxvf nginx-1.8.0.tar.gz
  4.  
    $ cd nginx-1.8.0
  5.  
    $ ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
  6.  
    (注: --with-http_ssl_module:这个不加后面在nginx.conf配置ssl:on后,启动会报nginx: [emerg] unknown directive "ssl" in /opt/nginx/conf/nginx.conf 异常)
  7.  
    $ make && make install
     
    ------------------------------------------------------------------------------------------- 
    参考地址:https://www.cnblogs.com/zhoading/p/11001773.html
     
    张家口编译安装参数:
    ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module --with-openssl=/java/openssl-1.1.1c --with-stream --with-pcre=/java/pcre-8.38

    1.4.安装nginx

    若安装时找不到上述依赖模块,使用--with-openssl=<openssl_dir>、--with-pcre=<pcre_dir>、--with-zlib=<zlib_dir>指定依赖的模块目录。如已安装过,此处的路径为安装目录;若未安装,则此路径为编译安装包路径,nginx将执行模块的默认编译安装。

    启动nginx之后,浏览器中输入http://localhost可以验证是否安装启动成功。

     --------------------------------------------------------------------------------------------

    3.查找安装路径:

    whereis nginx
    
    修改配置文件 nginx.config
    4.关闭防火墙 CentOS 7.0默认使用的是firewall作为防火墙

    查看防火墙状态

    firewall-cmd --state
    • 1

    停止firewall

    systemctl stop firewalld.service
     
     

    启动、停止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

    启动成功后,在浏览器可以看到这样的页面:

    nginx-welcome.png

    开机自启动

    即在rc.local增加启动代码就可以了。

    vi /etc/rc.local

    增加一行 /usr/local/nginx/sbin/nginx
    设置执行权限:

    chmod 755 rc.local

    nginx-rclocal.png

    到这里,nginx就安装完毕了,启动、停止、重启操作也都完成了,当然,你也可以添加为系统服务,我这里就不在演示了。

     

posted on   四海骄阳  阅读(338)  评论(0编辑  收藏  举报

编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
· 全程使用 AI 从 0 到 1 写了个小工具
历史上的今天:
2018-01-18 如何有效利用时间
2018-01-18 软件设计师考试心得
2018-01-18 Spring:源码解读Spring IOC原理
2018-01-18 【HTTP】Fiddler(二) - 使用Fiddler做抓包分析

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示