zoukankan      html  css  js  c++  java
  • 编译安装和apt安装Nginx1.14.0

    安装依赖

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

    在Ubuntu 下, 对应需要安装的是

    sudo apt install build-essential libpcre3 libpcre3-dev libssl-dev zlib1g zlib1g-dev
    

    建立用户及用户组

    groupadd -r nginx
    # -r 表示创建的是系统组
    useradd -s /sbin/nologin -g nginx -r nginx
    # -r 表示创建的是系统用户
    id nginx
    # 即使用其他用户启动nginx, 也必须创建nginx用户和用户组, 否则会出现 nginx: [emerg] getpwnam("nginx") failed 错误

    编译和安装

    ./configure --prefix=/opt/nginx/nginx-1.14.0 --user=nginx --group=nginx --with-http_gzip_static_module --with-pcre --with-http_ssl_module --with-http_flv_module --with-stream --with-stream_ssl_module --with-http_stub_status_module
    make
    make install

    如果需要rtmp服务, 需要加上rtmp模块

    git clone https://github.com/arut/nginx-rtmp-module.git
    
    ./configure --prefix=/opt/nginx/nginx-1.18.0 --user=nginx --group=nginx --with-http_gzip_static_module --with-pcre --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --add-module=/home/milton/backup/nginx-rtmp-module
    

    建立latest目录和软链, 方便将来替换为新版本

    cd /opt/nginx/
    ln -s nginx-1.14.0 latest

    配置

    将nginx加入系统服务

    cd /lib/systemd/system/
    vi nginx.service
    
    # 内容
    
    [Unit]
    Description=The NGINX HTTP and reverse proxy server
    After=syslog.target network.target remote-fs.target nss-lookup.target
    
    [Service]
    Type=forking
    PIDFile=/var/run/nginx.pid
    ExecStartPre=/opt/nginx/latest/sbin/nginx -t -c /opt/nginx/latest/conf/nginx.conf
    ExecStart=/opt/nginx/latest/sbin/nginx
    ExecReload=/opt/nginx/latest/sbin/nginx -s reload
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
    # 内容结束
    
    systemctl enable nginx.service

    打开端口启动服务

    firewall-cmd --zone=public --list-all
    firewall-cmd --zone=public --add-service=http --permanent
    firewall-cmd --reload
    
    # 启动nginx
    systemctl start nginx

    Ubuntu18.04下apt安装Nginx1.14.0

    Ubuntu18.04下默认的nginx版本就是1.14.0, 可以直接通过 sudo apt install nginx 安装. 安装后会自动加入service并启动, 可以通过 sudo systemctl list-unit-files 检查

    默认的配置文件位于 /etc/nginx/nginx.conf, 这是给Ubuntu定制的配置文件, 基础配置部分, 会加载 /etc/nginx/modules-enabled/*.conf , 在 http 部分, 会自动加载 include /etc/nginx/conf.d/*.conf 和 include /etc/nginx/sites-enabled/*, 这样方便用户通过 modules-enabled, modules-available 和 sites-enabled, sites-available 来管理可用站点.

    从这里开始配置就和编译安装的一样了.

  • 相关阅读:
    Spring Boot:自动配置原理
    centos7安装zookeeper
    spring集成RabbitMQ
    centos7安装RabbitMQ
    centos7安装MongoDB4.0(yum安装)
    nginx日志分割
    centos7 yum安装nginx
    centos7使用cronolog分割tomcat8.5的catalina.out日志
    ubuntu18安装微信
    idea打开dashboard
  • 原文地址:https://www.cnblogs.com/milton/p/9693836.html
Copyright © 2011-2022 走看看