5 nginx 安装小记

Posted abel2020

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5 nginx 安装小记相关的知识,希望对你有一定的参考价值。

编译安装:

    下载: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 安装小记的主要内容,如果未能解决你的问题,请参考以下文章

菜鸟运维笔记:小记编译安装Nginx所遇到的坑

nginx使用小记

docker安装php容器小记

Manjaro安装mysql-5.7折腾小记

Ubuntu 16.04 安装Mysql 5.7 踩坑小记

Linux安装Redis小记