开发前后端分离时,我们经常会部署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; } }