美文网首页
2019-12-20

2019-12-20

作者: 张俊庆 | 来源:发表于2019-12-21 22:43 被阅读0次

    Nginx 安装

    安装环境:CentOS Linux release 7.6
    安装nginx版本:1.16.1

    $cat /etc/redhat-release
    
    CentOS Linux release 7.6.1810 (Core)
    

    1、安装步骤

    $yum install gcc-c++

    $yum install -y pcre pcre-devel

    $yum install -y zlib zlib-devel

    $yum install -y openssl openssl-devel

    $wget http://nginx.org/download/nginx-1.16.1.tar.gz

    $tar -zxvf nginx-1.16.1.tar.gz -C /usr/local

    $cd /usr/local/nginx-1.16.1

    $./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tem/nginx/client --http-proxy-temp-path=/var/tem/nginx/proxy --http-fastcgi-temp-path=/var/tem/nginx/fcgi --with-http_stub_status_module

    ......
    creating objs/Makefile
    
    Configuration summary
      + using system PCRE library
      + using system OpenSSL library
      + using system zlib library
    
      nginx path prefix: "/usr"
      nginx binary file: "/usr/sbin/nginx"
      nginx modules path: "/usr/modules"
      nginx configuration prefix: "/etc/nginx"
      nginx configuration file: "/etc/nginx/nginx.conf"
      nginx pid file: "/var/run/nginx/nginx.pid"
      nginx error log file: "/var/log/nginx/error.log"
      nginx http access log file: "/var/log/nginx/access.log"
      nginx http client request body temporary files: "/var/tem/nginx/client"
      nginx http proxy temporary files: "/var/tem/nginx/proxy"
      nginx http fastcgi temporary files: "/var/tem/nginx/fcgi"
      nginx http uwsgi temporary files: "uwsgi_temp"
      nginx http scgi temporary files: "scgi_temp"
    

    $make && make install

    2、启动

    nginx -c /etc/nginx/nginx.conf

    3、Trouble Shooting

    出现[emerg] getpwnam("nginx") failed 错误

    $useradd -s /sbin/nologin -M nginx
    $id nginx
    

    出现nginx: [emerg] mkdir() "/var/tem/nginx/client" failed (2: No such file or directory)

    sudo mkdir -p /var/tem/nginx/client
    

    如果您正在运行防火墙,请运行以下命令以允许HTTP和HTTPS通信

    sudo firewall-cmd --permanent --zone=public --add-service=http 
    sudo firewall-cmd --permanent --zone=public --add-service=https
    sudo firewall-cmd --reload
    

    4、重启

    可选方法如下:

    4.1、进入nginx可执行目录sbin下,输入命令./nginx -s reload 即可

    $cd /usr/sbin
    $ls -lh nginx 
    $./nginx -s reload
    

    4.2、查找当前nginx进程号,然后输入命令:kill -HUP 进程号 实现重启nginx服务

    $ps -ef | grep nginx
    root     18446     1  0 18:35 ?        00:00:00 nginx: master process nginx -c /etc/nginx/nginx.conf
    nginx    18448 18446  0 18:35 ?        00:00:00 nginx: worker process
    root     18487 13105  0 18:39 pts/2    00:00:00 grep --color=auto nginx
    $kill -HUP 18446
    

    5、停止

    $cd /usr/sbin
    $ls -lh nginx 
    $./nginx -s stop
    

    6、帮助

    $cd /usr/sbin
    $ls -lh nginx 
    $./nginx -h
    nginx version: nginx/1.16.1
    Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
    
    Options:
      -?,-h         : this help
      -v            : show version and exit
      -V            : show version and configure options then exit
      -t            : test configuration and exit
      -T            : test configuration, dump it and exit
      -q            : suppress non-error messages during configuration testing
      -s signal     : send signal to a master process: stop, quit, reopen, reload
      -p prefix     : set prefix path (default: /usr/)
      -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
      -g directives : set global directives out of configuration file
    

    7、查看版本

    $cd /usr/sbin
    $ls -lh nginx 
    $./nginx -v
    nginx version: nginx/1.16.1
    

    8、安装验证

    访问ip地址:http://10.18.18.18/

    image.png

    相关文章

      网友评论

          本文标题:2019-12-20

          本文链接:https://www.haomeiwen.com/subject/tgbinctx.html