zoukankan      html  css  js  c++  java
  • nginx安装

    https://www.cnblogs.com/hejun695/p/5367374.html
    
    https://www.cnblogs.com/piscesLoveCc/p/5867900.html

    https://blog.csdn.net/qq_36454337/article/details/81136775 1、安装依赖包 [root@host-10-1-1-161 ~]# yum -y install gcc gcc-c++ autoconf automake [root@host-10-1-1-161 ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre-devel [root@host-10-1-1-161 ~]# yum -y install gcc automake autoconf libtool gcc-c++ gd zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel pcre pcre-devel 2、安装nginx [root@host-10-1-1-161 ~]# cd /usr/local [root@host-10-1-1-161 local]# wget http://nginx.org/download/nginx-1.9.9.tar.gz [root@host-10-1-1-161 local]#tar xf nginx-1.9.9.tar.gz [root@host-10-1-1-161 local]# cd nginx-1.9.9 [root@ecs-01 nginx-1.9.9]# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --with-stream --with-http_stub_status_module --with-http_ssl_module #这个为主,不行的话再用下面 [root@ecs-01 nginx-1.9.9]# ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --with-stream --with-http_stub_status_module --with-http_ssl_module [root@ecs-01 nginx-1.9.9]# make [root@ecs-01 nginx-1.9.9]# make install
    [root@ecs-01 nginx-1.9.9]# echo 'export PATH=$PATH:/usr/local/nginx/sbin' >> /etc/profile
    [root@host-10-1-1-161 logs]# /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf

    添加开机自启文件

    [root@bogon ~]# cat /lib/systemd/system/nginx.service 
    #!/bin/bash
    [Unit]
    Description=nginx
    After=network.target

    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s quit
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

    设置nginx服务开机自启

    [root@bogon ~]# systemctl enable nginx

    启动nginx方式一、

    nginx //启动

    nginx -t //检查配置文件是否正常
    nginx -s reload //重新载入配置文件
    nginx -s stop //停止
    nginx -s reopen //重启

    启动nginx方式二、

    启动nginx服务

    systemctl start nginx.service
     
    设置开机自启动
    systemctl enable nginx.service

    停止开机自启动
    systemctl disable nginx.service

    查看服务当前状态
    systemctl status nginx.service

    重新启动服务
    systemctl restart nginx.service

    查看所有已启动的服务
    systemctl list-units --type=service


    3、安装完成后加上下面两句话,否则报错
    
    
    重要:修改配置文件使用虚拟机,否则怎么配置都不生效,添加如下用户
    
    [root@host-10-1-1-161 html]# ll /etc/nginx/nginx.conf
    -rw-r--r-- 1 root root 345 Aug 26 10:41 /etc/nginx/nginx.conf
    [root@host-10-1-1-161 html]# vi /etc/nginx/nginx.conf
    user root root;                      #说明:这里的user根据 自己的nginx.conf文件所在的目录的属主属性而定 
    worker_processes 1;
    
    
    --with-stream  ---支持TCP的意思
    
    
    
    
    4、设置Nginx开机启动
    
    
    编辑/etc下的rc.local文件
    # vi /etc/rc.local
    添加:
    /usr/local/nginx/sbin/nginx
    
    
    
    
    
    
    5、使用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
    先停止在启动(推荐),对 nginx 进行重启相当先停止再启动,即先执行停止命令再执行启动命令
    
    ./nginx -s quit
    ./nginx
    重新加载配置文件,当 nginx 的配置 nginx.conf 修改后,想让配置生效需要重启 nginx,使用 -s reload 不用先停止 nginx 再 nginx 即可配置信息在 nginx 中生效,如下:
    
    ./nginx -s reload
    
    
    
    
    
    报错解决:
    
    
    1、centos安装nginx 报错:cp: `conf/koi-win' and `/usr/local/nginx/conf/koi-win' are the same file
    
    解决:
    
    删除/usr/local下的nginx,建一个空的nginx文件夹
    
    将这一步改一下
    
    ./configure --prefix=/usr/local/nginx  
    
    TO
    
    ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf 
    
    
    
    
    2、nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
    
    [root@host-10-1-1-161 ~]# nginx -s reload
    nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
    [root@host-10-1-1-161 nginx]# cd /usr/local/nginx/logs/
    [root@host-10-1-1-161 logs]# ls
    access.log  error.log  nginx.pid
    [root@host-10-1-1-161 logs]# rm -rf nginx.pid 
    
    
    
    3、nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
    
    [root@host-10-1-1-161 ~]# nginx -s reload
    nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
    [root@host-10-1-1-161 logs]# /usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
    [root@host-10-1-1-161 logs]# /usr/local/nginx/sbin/nginx -s reload
    [root@host-10-1-1-161 logs]# nginx -s reload
  • 相关阅读:
    前沿技术解密——VirtualDOM
    Ques核心思想——CSS Namespace
    Unix Pipes to Javascript Pipes
    Road to the future——伪MVVM库Q.js
    聊聊CSS postproccessors
    【译】十款性能最佳的压缩算法
    Kafka Streams开发入门(9)
    Kafka Streams开发入门(8)
    【译】Kafka Producer Sticky Partitioner
    【译】99th Percentile Latency at Scale with Apache Kafka
  • 原文地址:https://www.cnblogs.com/effortsing/p/10011450.html
Copyright © 2011-2022 走看看