只需要http访问的
0. 关闭云服务器的防火墙
bash
1. 把本地的vue项目编译打包 把dist文件夹压缩成dist.zip,并上传到服务器上。
2. 线上操作,解压缩
bash
# 没有unzip 就 yum install unzip
unzip dist.zip
2. 配置nginx 这里保证你的nginx已经安装好,vim编辑ngin的配置文件。
bash
server{
listen 80;
server_name localhost;
gzip on;
gzip_static on;
gzip_min_length 1k;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 2;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/jpeg image/gif image/png image/svg+xml;
add_header Cache-Control "max-age=31536000,immutable";
location / {
try_files $uri $uri/ @rewrites;
root /hongBrain/dist;
index index.html;
autoindex on;
}
location @rewrites {
rewrite ^.*$ /index.html last;
}
}
然后平滑重启nginx:
bash
nginx -t
nginx -s reload
完事浏览器直接访问云服务器的公网IP即可,注意,保证云服务器的防火墙是关闭的,安全组的80端口是开放的。
支持https访问的nginx配置
至于域名购买、ssl证书的申请、备案等都需要你自己来完成,这里默认是都搞定的状态,我这里直接列出重点的nginx配置。
bash
server{
listen 80;
#请填写绑定证书的域名,即web.neeo.cc
server_name web.neeo.cc;
#把http的域名请求转成https
# rewrite ^(.*)$ https://web.neeo.cc permanent;
return 301 https://$host$request_uri;
}
server {
#SSL 默认访问端口号为 443
listen 443 ssl;
server_name web.neeo.cc;
ssl_certificate /scm3/web.neeo.cc_nginx/web.neeo.cc_bundle.crt;
ssl_certificate_key /scm3/web.neeo.cc_nginx/web.neeo.cc.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
gzip on;
gzip_static on;
gzip_min_length 1k;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 2;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/jpeg image/gif image/png image/svg+xml;
add_header Cache-Control "max-age=31536000,immutable";
location / {
try_files $uri $uri/ @rewrites;
root /scm3/dist;
index index.html;
autoindex on;
}
location @rewrites {
rewrite ^.*$ /index.html last;
}
}