• Centos7下安装Nginx


    一、安装步骤

      1. 检查并安装所需的依赖软件

        1).gcc:nginx编译依赖gcc环境

         安装命令:yum install gcc-c++

        2).pcre:(Perl Compatible Regular Expressions)是一个Perl库,包括perl兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式.

         安装命令:yum install -y pcre pcre-devel

        3).zlib:该库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip。

         安装命令:yum install -y zlib zlib-devel

        4).openssl:一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http).

         安装命令:yum install -y openssl openssl-devel

    2.下载nginx源码包

        下载命令:wget http://nginx.org/download/nginx-1.12.0.tar.gz

      

    3.解压缩源码包并进入

        1).解压缩:tar -zxvf nginx-1.12.0.tar.gz

        2).进入解压缩后文件夹:cd nginx-1.12.0

      4.配置编译参数(可以使用./configure --help查询详细参数)

        命令:

        ./configure
        > --prefix=/usr/local/nginx

    > --sbin-path=/usr/sbin/nginx

    > --conf-path=/etc/nginx/nginx.conf

    > --error-log-path=/var/log/nginx/error.log

    > --http-log-path=/var/log/nginx/access.log

    > --pid-path=/var/run/nginx.pid

    > --lock-path=/var/run/nginx.lock

    > --http-client-body-temp-path=/var/tmp/nginx/client

    > --http-proxy-temp-path=/var/tmp/nginx/proxy

    > --http-fastcgi-temp-path=/var/tmp/nginx/fcgi

    > --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi

    > --http-scgi-temp-path=/var/tmp/nginx/scgi

    > --user=nginx

    > --group=nginx

    > --with-pcre

    > --with-http_v2_module

    > --with-http_ssl_module

    > --with-http_realip_module

    > --with-http_addition_module

    > --with-http_sub_module

    > --with-http_dav_module

    > --with-http_flv_module

    > --with-http_mp4_module

    > --with-http_gunzip_module

    > --with-http_gzip_static_module

    > --with-http_random_index_module

    > --with-http_secure_link_module

    > --with-http_stub_status_module

    > --with-http_auth_request_module

    > --with-mail

    > --with-mail_ssl_module

    > --with-file-aio

    > --with-ipv6

    > --with-http_v2_module

    > --with-threads

    > --with-stream

    > --with-stream_ssl_module  

      注:安装之前需要手动创建上面指定的nginx文件夹,即/var/temp、/var/temp/nginx、/var/run/nginx/文件夹,否则启动时报错

      

    5.编译并安装

        命令:make && make install

        可以进入/usr/local/nginx查看文件是否存在conf、sbin、html文件夹,若存在则安装成功

      6.启动nginx

        1).进入安装目录

          cd /usr/local/nginx/sbin/

        2).启动

          ./nginx

        3).若报错:[emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)

          需要查看下是不是在/var/run文件夹下不存在nginx文件夹,不存在则新建

        4).查看是否启动:ps -ef | grep nginx

          如果有master和worker两个进程证明启动成功

          

        注意:执行./nginx启动nginx,这里可以-c指定加载的nginx配置文件,如下:

        ./nginx -c /usr/local/nginx/conf/nginx.conf

        如果不指定-c,nginx在启动时默认加载conf/nginx.conf文件,此文件的地址也可以在编译安装nginx时指定./configure的参数(--conf-path= 指向配置文件(nginx.conf))

      

    7.停止

        1).暴利kill(不推荐使用)

          kill -9 processId

        2).快速停止

          cd /usr/local/nginx/sbin && ./nginx -s stop

          此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程

        3).完整停止(建议使用)

          cd /usr/local/nginx/sbin && ./nginx -s quit

          此方式停止步骤是待nginx进程处理任务完毕进行停止

      8.重启及重新加载配置

        1.先停止再启动(建议使用)

          ./nginx -s quit && ./nginx

        2.重新加载配置文件
          ./nginx -s reload

      9.测试

        nginx安装成功,启动nginx,即可通过ip地址来访问nginx:

  • 相关阅读:
    uvm_pkg——老板,打包带走
    uvm.sv——UVM之道
    uvm_comps.svh
    uvm_subscriber——告诉她我们来过
    uvm_monitor——借我一双慧眼
    编程面试过程中常见的10大算法(转)
    MySQL 分区表
    Nginx + Tomcat 动静分离实现负载均衡(转)
    浅析JVM内存结构和6大区域(转)
    Linux Shell编程变量赋值和引用
  • 原文地址:https://www.cnblogs.com/cyz123/p/11995644.html
Copyright © 2020-2023  润新知