• nginx----(1)nginx的单机安装



    image-20221020214026245
    image-20221020214026245
    image-20221020214133585

    Nginx卸载

    步骤一:需要将nginx的进程关闭

    ./nginx -s stop
    
    • 1

    步骤二:将安装的nginx进行删除

    rm -rf /usr/local/nginx
    
    • 1

    步骤三:将安装包之前编译的环境清除掉

    make clean
    
    • 1

    开源版Nginx安装

    默认简单安装

    1. cd /usr/local 下,下载nginx软件 wget http://nginx.org/download/nginx-1.21.3.tar.gz
    2. 解压 tar -zxvf nginx-1.21.3.tar.gz
    3. 进入 cd nginx-1.21.3
    4. 安装依赖环境
    • yum -y install pcre pcre-devel
    • yum -y install zlib zlib-devel
    • yum -y install openssl openssl-devel

    ​ 或者一步执行 yum -y install gcc zlib-devel pcre-devel openssl openssl-devel

    1. 安装nginx
    • 在解压后的文件夹中 ./configure
    • make
    • make install (安装完会在/usr/local/下有一个nginx目录)
    1. 启动nginx: cd /usr/local/nginx/sbin ./nginx
    2. 查看nginx服务状态: ps -ef | grep nginx
    3. 测试nginx服务: http://xxxx.xxx.xxx

    Nginx的源码复杂安装

    Nginx的安装目录,默认值为/usr/local/nginx

    --prefix=PATH
    
    • 1

    (执行)程序文件(nginx)的路径,默认值为/sbin/nginx

    --sbin-path=PATH
    
    • 1

    Nginx动态模块安装目录,默认值为/modules

    --modules-path=PATH
    
    • 1

    配置文件(nginx.conf)的路径,默认值为 /conf/nginx.conf

    --conf-path=PATH
    
    • 1

    错误日志文件的路径,默认值为/logs/error.log

    --error-log-path=PATH
    
    • 1

    访问日志文件的路径,默认值为/logs/access.log

    --http-log-path=PATH
    
    • 1

    Nginx启动后进行ID的文件路径,默认值为 /logs/nginx.pid

    --pid-path=PATH
    
    • 1

    Nginx锁文件的存放路径,默认值为/logs/nginx.lock

    --lock-path=PATH
    
    • 1

    要想使用可以通过如下命令

    ./configure --prefix=/usr/local/nginx \
    --sbin-path=/usr/local/nginx/sbin/nginx \
    --modules-path=/usr/local/nginx/modules \
    --conf-path=/usr/local/nginx/conf/nginx.conf \
    --error-log-path=/usr/local/nginx/logs/error.log \
    --http-log-path=/usr/local/nginx/logs/access.log \
    --pid-path=/usr/local/nginx/logs/nginx.pid \
    --lock-path=/usr/local/nginx/logs/nginx.lock
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    make && make install
    
    • 1

    防火墙问题

    常用命令

    关闭防火墙

    systemctl stop firewalld.service

    禁止防火墙开机启动

    systemctl disable firewalld.service

    放行端口

    firewall-cmd --zone=public --add-port=80/tcp --permanent

    重启防火墙

    firewall-cmd --reload

    在 windows 系统中访问 linux 中 nginx,默认不能访问的,因为防火墙问题
    (1关闭防火墙
    (2开放访问的端口号,80 端口

    查看防火墙状态,临时关闭防火墙,并访问
    systemctl status firewalld
    systemctl stop firewalld
    访问即可

    如果想要永久关闭防火墙
    systemctl disable firewalld.service 开机不启动
    systemctl enable firewalld.service 设置开机启动
    systemctl start firewalld.service 开启防火墙

    如果需要开启防火墙时访问,可以使用如下
    查看开放的端口号
    firewall-cmd --list-all

    设置开放的端口号
    firewall-cmd --add-service=http –permanent
    firewall-cmd --add-port=80/tcp --permanent

    重启防火墙
    firewall-cmd –reload

    nginx启停

    进入安装好的目录 /usr/local/nginx/sbin

    ./nginx 启动 
    
    ./nginx -s stop 快速停止 
    
    ./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求 
    
    ./nginx -s reload 重新加载配置
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    安装成系统服务

    创建服务脚本

    vi /usr/lib/systemd/system/nginx.service
    
    • 1

    服务脚本内容

    [Unit] 
    Description=nginx - web server 
    After=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 -c /usr/local/nginx/conf/nginx.conf 
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 
    ExecReload=/usr/local/nginx/sbin/nginx -s reload 
    ExecStop=/usr/local/nginx/sbin/nginx -s stop 
    ExecQuit=/usr/local/nginx/sbin/nginx -s quit 
    PrivateTmp=true 
    
    [Install] 
    WantedBy=multi-user.target
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    重新加载系统服务

    systemctl daemon-reload

    启动服务

    systemctl start nginx.service

    开机启动

    systemctl enable nginx.service

  • 相关阅读:
    c# HookProc 钩子
    Windows如何运行anywhere
    Reflections一个强大的类扫描工具介绍
    贪吃蛇(C语言)步骤讲解
    Java 如何检测Map集合中是否包含指定key呢?
    漏洞复现 - - - Fastjson反序列化漏洞
    IP179N NI H Hl参考资料和引脚图
    JavaSE - 类和对象
    Fink--3、Flink运行时架构(并行度、算子链、任务槽、作业提交流程)
    分布式缓存--缓存与数据库强一致场景下的方案
  • 原文地址:https://blog.csdn.net/weixin_44235759/article/details/127436660