• linux安装nginx


    1、安装依赖项

    yum -y install \
    gcc \
    gcc-c++ \
    make \
    pcre-devel \
    expat-devel \
    perl \
    zlib*
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    nginx1.21.6版本链接:https://pan.baidu.com/s/1ggoD250o1HgdDqYdzkbZtw
    提取码:spnm

    2、将压缩包上传到服务器并解压,进入解压后的nginx目录

    cd nginx-1.21.6/
    
    • 1

    进行相关配置,指定安装目录,启用http_stub_status_module统计模块(统计多少人访问)

    ./configure \
    > --prefix=/usr/local/nginx \
    > --with-http_stub_status_module
    
    • 1
    • 2
    • 3

    安装

    make && make install
    
    • 1

    以便管理员直接执行“nginx”命令就可以调用Nginx的主程序为主程序nginx以及配置文件创建连接文件,以便管理员直接执行“nginx”命令就可以调用Nginx的主程序

    ln -s /usr/local/nginx/conf/nginx.conf /etc/
    
    • 1
    ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
    
    • 1

    检测nginx配置文件是否正常

    nginx -t
    
    • 1

    启动nginx

    nginx
    
    • 1

    浏览器输入服务器公网ip地址显示如下信息代表安装成功
    在这里插入图片描述

    3、域名配置

    vim /usr/local/nginx/conf/nginx.conf
    
    • 1

    在配置文件的server对象后面追加新的server对象,其中一个server对象代表一个项目,一个项目一个域名

    server {
            listen       80;
            server_name  a.baidu.com;
    		error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            location / {
                root   /www/wwwroot/tp5;
                index  index.php index.html index.htm;
            }
    }
    server {
            listen       80;
            server_name  b.baidu.com;
    		error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            location / {
                root   /www/wwwroot/laravel;
                index  index.php index.html index.htm;
            }
        }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    server对象中的server_name 表示你备案通过的域名
    location对象中的root表示你的项目的路径
    location对象中的index表示使用域名时的默认访问文件

    4、设置nginx自启动

    cd /etc/systemd/system
    
    • 1
     vi nginx.service
    
    • 1

    讲一下内容粘贴到nginx.service文件中

    [Unit]
    Description=nginx service
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/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
    systemctl enable nginx
    
    • 1
  • 相关阅读:
    AcWing 1282. 搜索关键词【AC自动机】
    Clickhouse-CPU内存资源优化配置
    C float Memory Representation
    Vue3学习(二十四)- 文档页面功能开发
    【计算机网络】运输层:可靠传输的工作原理(1)停止等待协议
    Android开发 对接微信分享SDK总结
    Windows Server 2012 R2 安装 OpenSSH
    虚拟机安装Docker装载Mysql
    typeScript--[interface接口实现类的定义,函数定义,可索引定义]
    JAVA面试
  • 原文地址:https://blog.csdn.net/qq_40787608/article/details/125629057