码迷,mamicode.com
首页 > 其他好文 > 详细

5 nginx 安装小记

时间:2020-06-14 13:14:28      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:error   esc   安装   fork   systemctl   uwsgi   内容   referer   ant   

编译安装:

    下载:http://nginx.org/download/nginx-1.18.0.tar.gz
    
    解压:tar -zxvf nginx-1.18.0.tar.gz
    
    configure:
 ./configure --prefix=/usr/local/soft/nginx-1.18.0 --with-http_stub_status_module --with-http_ssl_module
    

#  nginx path prefix: "/usr/local/soft/nginx-1.18.0"
#  nginx binary file: "/usr/local/soft/nginx-1.18.0/sbin/nginx"
#  nginx modules path: "/usr/local/soft/nginx-1.18.0/modules"
#  nginx configuration prefix: "/usr/local/soft/nginx-1.18.0/conf"
#  nginx configuration file: "/usr/local/soft/nginx-1.18.0/conf/nginx.conf"
#  nginx pid file: "/usr/local/soft/nginx-1.18.0/logs/nginx.pid"
#  nginx error log file: "/usr/local/soft/nginx-1.18.0/logs/error.log"
#  nginx http access log file: "/usr/local/soft/nginx-1.18.0/logs/access.log"
#  nginx http client request body temporary files: "client_body_temp"
#  nginx http proxy temporary files: "proxy_temp"
#  nginx http fastcgi temporary files: "fastcgi_temp"
#  nginx http uwsgi temporary files: "uwsgi_temp"
#  nginx http scgi temporary files: "scgi_temp"

     make && make install        

    
    查看版本:/usr/local/soft/nginx-1.18.0/sbin/nginx -v

1 配置启动:

    
[root@centos8 conf]# mkdir /data/nginx
[root@centos8 conf]# mkdir /data/nginx/logs

 

2,运行的准备工作:创建nginx用户

[root@centos8 conf]# groupadd nginx

#-g:指定所属的group

#-s:指定shell,因为它不需要登录,所以用/sbin/nologin

#-M:不创建home目录,因为它不需要登录

[root@centos8 conf]# useradd -g nginx -s /sbin/nologin -M nginx

 

3,简单配置nginx
# cd /usr/local/soft/nginx-1.18.0
# cp conf conf2
# cd conf
# vi nginx.conf

内容:

指定运行nginx的用户和组是:nginx

user nginx nginx;

 

发生错误时要写入到错误日志(目录用上面创建好的)

error_log   /data/nginx/logs/error.log;

 

指定pid的路径

pid        logs/nginx.pid;

 

日志格式(取消注释即可)

   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  /data/nginx/logs/access.log  main;

 

4,生成service文件:


    # vim /usr/lib/systemd/system/nginx.service

    [Unit]
    Description=nginx-The High-performance HTTP Server
    After=network.target

    [Service]
    Type=forking
    PIDFile=/usr/local/soft/nginx-1.18.0/logs/nginx.pid
    ExecStartPre=/usr/local/soft/nginx-1.18.0/sbin/nginx -t -c /usr/local/soft/nginx-1.18.0/conf/nginx.conf
    ExecStart=/usr/local/soft/nginx-1.18.0/sbin/nginx -c /usr/local/soft/nginx-1.18.0/conf/nginx.conf
    ExecReload=/usr/local/soft/nginx-1.18.0/sbin/nginx -s reload
    ExecStop=/usr/local/soft/nginx-1.18.0/sbin/nginx -s stop
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

5 重新加载服务文件
    # systemctl daemon-reload

   启动: systemctl start nginx

6 测试 ,web登录

7 查看日志
    # ll /data/nginx/logs/




5 nginx 安装小记

标签:error   esc   安装   fork   systemctl   uwsgi   内容   referer   ant   

原文地址:https://www.cnblogs.com/abel2020/p/13124339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!