Nginx源码安装

环境

系统:CentOS 6.9 或 CentOS 7.4
软件:nginx-1.12.1.tar.gz

Nginx安装

  • 下载源码包
    地址:http://nginx.org/

  • 添加账户

    # useradd nginx
    
  • 安装依赖包

    # yum -y install gcc automake pcre-devel zlib-devel openssl-devel
    
  • 编译安装

    # tar -zxvf nginx-1.12.1.tar.gz
    # cd nginx-1.12.1
    
    # ./configure \
    --prefix=/usr/local/nginx \
    --with-http_stub_status_module \
    --with-http_ssl_module \
    --with-stream
    
    # make
    # make install
    
  • 配置环境变量

    # vim /etc/profile
    export PATH=/usr/local/nginx/sbin:$PATH
    
    # source /etc/profile
    

Nginx配置

  • 编辑配置文件

    # ln -s /usr/local/nginx/conf /etc/nginx
    
    # vim /etc/nginx/nginx.conf
    user  nginx;
    pid  /var/run/nginx.pid;
    
    http {
    ....
    access_log  off;
    client_max_body_size 128M;
    include  /etc/nginx/conf.d/*.conf;
    }
    
  • 创建文件夹

    # mkdir /etc/nginx/conf.d
    # mkdir /var/log/nginx
    # chown -R nginx:nginx /var/log/nginx
    

Nginx启动

CentOS 6.9

  • 添加启动服务

    # wget https://raw.githubusercontent.com/yuantong127/ansible/master/roles/nginx-install/files/nginxd
    # mv nginxd /etc/init.d/nginxd
    # chmod +x /etc/init.d/nginxd
    
  • 启动

    # chkconfig --add nginxd
    # chkconfig nginxd on
    # /etc/init.d/nginxd start
    

CentOS 7.4

  • 添加启动服务

    # vim /usr/lib/systemd/system/nginx.service
    [Unit]
    Description=nginx - high performance web server
    Documentation=http://nginx.org/en/docs/
    After=network.target remote-fs.target nss-lookup.target
    
    [Service]
    Type=forking
    PIDFile=/var/run/nginx.pid
    ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
  • 启动

    # systemctl enable nginx.service
    # systemctl stop nginx.service
    

你可能感兴趣的:(Nginx源码安装)