zoukankan      html  css  js  c++  java
  • nginx安装,运行(ubuntu)

    文本只涉及单节点nginx

    安装gcc g++依赖库

    apt-get install build-essential
    apt-get install libtool

    安装pcre依赖库

    apt-get update
    apt-get install libpcre3 libpcre3-dev

    安装zlib依赖库

    apt-get install zlib1g-dev

    安装ssl依赖库

    apt-get install openssl

    下载并安装

    wget -P /opt/downloads http://nginx.org/download/nginx-1.15.9.tar.gz
    tar zxvf /opt/downloads/nginx-1.15.9.tar.gz -C /opt
    cd /opt/nginx-1.15.9
    ./configure
    ./configure --prefix=/opt/nginx make make install

    修改nginx配置

    vim /usr/local/nginx/conf/nginx.conf

    放出pid

    error_log  logs/error.log;
    error_log  logs/error.log  notice;
    error_log  logs/error.log  info;
    
    pid        logs/nginx.pid;

     去掉http节点下某些注释(非必须)

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  logs/access.log  main;

    验证配置文件

    /usr/local/nginx/sbin/nginx -t 

    启动

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

    注:-c 指定配置文件的路径,不加的话,nginx会自动加载默认路径的配置文件,可以通过 -h查看帮助命令。

    停止

    /usr/local/nginx/sbin/nginx -s stop

    帮助

    /usr/local/nginx/sbin/nginx -h

    守护进程启动:

    vim /lib/systemd/system/nginx.service
    [Unit]
    Description=nginx
    After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type
    =forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    ExecStartPre=
    /usr/local/nginx/sbin/nginx -t
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    ExecReload=/usr/local/nginx/sbin/nginx -s reload -c /usr/local/nginx/conf/nginx.conf
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target

    赋予权限

    chmod 777 /lib/systemd/system/nginx.service

    启用守护进程

    systemctl enable nginx.service
    systemctl daemon-reload

    运行

    systemctl start nginx.service

    查看日志 

    journalctl -f -u nginx.service

    查看状态

    systemctl status nginx.service

    查看nginx进程

    ps -ef|grep nginx
  • 相关阅读:
    NETCore EF 数据库连接正确nuget和MySql错误异常
    JS 对象属性名排序
    NET 在一个数组中查找另一个数组所在起始位置(下标从0开始,未找到返回-1)
    NET 判断是否为回文
    NET/Regex 处理连续空格
    NET 已知excel表格前面26个是a到z,27是aa28是ab,以此类推,N是多少
    Regex 首字母转大写/小写,全大写,全小写
    .NETCore下访问img、js等静态资源404解决办法
    WPF-后台代码使用Behavior
    Socket-服务器端与客户端互相通信
  • 原文地址:https://www.cnblogs.com/wintersoft/p/10537946.html
Copyright © 2011-2022 走看看