1. 程式人生 > >Nginx部署靜態網站

Nginx部署靜態網站

文件夾 editor cat code san com pre div 沒有

前後端分離項目,前端項目要單獨部署到線上

前端以vue.js為例,代碼clone或pull到服務器上,編譯 npm run build ,此時生成 dist文件夾,既靜態資源網站的根目錄

此時配置nginx配置文件如下:

server {
    listen 80;
    server_name test.xxxx.com;
    location / {
        root  /home/zhangsan/www/XEditor/dist;
        index index.html;
    }
}

將根目錄改到了自己的家目錄下:/home/zhangsan/www

如果訪問提示403 forbidden:這個問題是因為沒有權限,一般情況是家目錄沒有權限,最暴力的方法就是把家目錄的權限改成 777

chmod 777 /home/zhangsan

Nginx部署靜態網站