Nginx部署H5專案

獵手家園發表於2021-11-22

開發前後端分離時,我們經常會部署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;
        }
}

 

相關文章