1.項目打包生成dist文件夾
在項目根目錄下打開cmd窗口,輸入命令
npm run build //生成dist文件夾
2.將dist文件夾上傳到centos7
使用scp命令或者用遠程連接工具將打包好的dist文件夾上傳到服務器或者虛擬機的某個位置。
打開cmd命令輸入: scp -r 22 E:\\dist root@192.168.3.5:/home/dist 輸入root 用戶密碼,等待上傳成功即可 E:\dist 為dist所在目錄 root 為虛擬機root用戶 192.168.3.5 為虛擬機ip /home/ 為將dist文件上傳虛擬機上home目錄
3.安裝nginx
推薦鏈接: https://www.cnblogs.com/kaid/p/7640723.html
4.nginx的幾個常用命令
//進入 /sbin目錄下 cd /usr/local/nginx/sbin //啟動nginx ./nginx //檢查更改的配置 ./nginx -t //重新加載 ./nginx -s reload //停止nginx ./nginx -s stop
5.修改nginx的conf配置
//進入conf cd /usr/local/nginx/conf vim nginx.conf
nginx.conf這個是全部的配置文件,可以復制下來參考。
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name 192.168.111.128; index index.html index.htm; root /app/fusionwork_deployment/web; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # index index.html index.htm; #} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
6.將端口的防火牆關掉
//8088,自己指定端口 firewall-cmd --permanent --add-port=8880/tcp --zone=public //重新加載 firewall-cmd --reload
7.重新加載配置,啟動nginx
//檢查配置是否正確 ./nginx -t //啟動nginx ./nginx
8.瀏覽器訪問本機虛擬機ip
http://192.168.111.128
可以看下這個,寫的比較詳細 https://blog.csdn.net/hotlinhao/article/details/88355125 http://www.pianshen.com/article/9593257962/