代码改变世界

Nginx部署H5项目

  猎手家园  阅读(5237)  评论(0编辑  收藏  举报

开发前后端分离时,我们经常会部署H5项目,不过这个操作非常简单。

1、首先我们将H5项目放到:/root/web/mypro 目录下

2、打开nginx.conf文件,增加如下:

(1)配置ip方法

复制代码
server {
        listen               8080;
        server_name          127.0.0.1;
        
        access_log           logs/h5_domain.local_access.log main;
        error_log            logs/h5_domain.local_error.log warn;

        location / {
            root             /root/web/mypro;
            index            index.html;
            try_files        $uri $uri/ /index.html;    #uniapp history模式刷新404问题
            autoindex        on;
            autoindex_exact_size on;
            autoindex_localtime  on;
        }
}
复制代码

 

(2)配置域名方法

复制代码
server {
        listen               80;
        server_name          h5.domain.com;
        
        access_log           logs/h5_domain.local_access.log main;
        error_log            logs/h5_domain.local_error.log warn;

        location / {
            root             /root/web/mypro;
            index            index.html;
            try_files        $uri $uri/ /index.html;    #uniapp history模式刷新404问题
            autoindex        on;
            autoindex_exact_size on;
            autoindex_localtime  on;
        }
}
复制代码

 

(3)配置Https方法

复制代码
server {
        listen 443 ssl;  #SSL 访问端口号 443
        server_name         h5.domain.com;
        #证书文件名称
        ssl_certificate     CA/h5.domain.local/1_h5.domain.com_bundle.crt;
        #私钥文件名称
        ssl_certificate_key CA/h5.domain.local/2_h5.domain.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        #配置加密套件,写法遵循 openssl 标准。
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;

        access_log           logs/h5_domain.local_access.log main;
        error_log            logs/h5_domain.local_error.log warn;

        location / {
            root             /root/web/mypro;
            index            index.html;
            try_files        $uri $uri/ /index.html;    #uniapp history模式刷新404问题
            autoindex        on;
            autoindex_exact_size on;
            autoindex_localtime  on;
        }
}
复制代码

 

编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示