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