1、安裝Nginx
- 我使用的是yum安裝,(當然也可以自己下載手動安裝),輸入命令查看yum上的nginx可用安裝包
yum list | grep nginx

- 安裝nginx,
yum -y install nginx

直到出現Complete! - 啟動nginx
systemctl start nginx - 查看nginx狀態
systemctl status nginx

正在運行,安裝完成,
2、build Vue專案
- 生成dist檔案
右鍵Vue專案→外部命令→npm run build→生成dist檔案 - 上傳dist檔案
使用rz工具或者Xftp工具,將dist檔案上傳到Linux系統,檔案位置根據自己需要,也可以自定義檔案名,(例如 /home/project/test)
3、部署Vue專案
- 首先,找到nginx的組態檔
nginx.conf
在啟動nginx查看其狀態時

我們可以看到組態檔的路徑,
當然我們也可以全域搜索find / -name nginx.conf

- 進入組態檔所在位置后打開組態檔 nginx.conf,為了簡單操作,我直接使用xftp來操作了
主要對server進行配置
server {
listen 8806; #監聽埠設定,也就是你vue專案的埠
server_name localhost;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /home/project/test; #前端dist檔案夾存放路徑
try_files $uri $uri/ /index.html; #解決頁面重繪報404錯誤
}
location /prod-api/{ #匹配/prod-api/
proxy_pass http://你的IP:你的埠/; #跳轉至后端的介面
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
配置完成!啟動nginx就可以訪問了,
4、Linux系統安全策略配置
OK!小編以為已經搞定了!訪問的時候,卻報錯了!
后來網上查閱資料,終于解決,解決方法如下:
-
找到檔案
/etc/selinux/config

-
打開檔案config

其中enforcing,permissive,disabled是Linux系統安全策略的三種模式,安全程度enforcing>permissive>disabled,小編沒有做深入研究,,, -
修改組態檔
只要把SELINUX=enforcing改為SELINUX=permissive即可,(當然改成disabled更可以)
- 重啟系統,啟動nginx,
發現此時專案可以正常訪問了!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/257727.html
標籤:其他
上一篇:硬碟掛載及測驗
