https://github.com/itguide/vnshop
## 啓動node服務php
npm i
cd /home/wwwroot/vnshop/server npm run start
npm i pm2 -g cd /home/wwwroot/vnshop/server pm2 start ./bin/www
http://vx.itnote.cn:3000/goods/list?sort=1&priceLevel=all&page=1&pageSize=8
若是返回數據,說明node 啓動正常css
後端node服務,啓動後是3000端口,在前臺vue項目中訪問,會產生跨域,在本地開發中咱們能夠配置代理來解決html
下面這個是詳細解決方案
https://segmentfault.com/a/11...vue
在 src/config/api.config.js
api.config 配置node
//判斷是開發模式仍是本地模式,其實不須要這麼麻煩 直接 const isPro = Object.is(process.env.NODE_ENV, 'production') module.exports = { baseUrl: isPro ? 'http://vx.itnote.cn/api/' : 'api/' }
注意:nginx
http://vx.itnote.cn/api/ 這個地址是你本身的服務,能訪問的服務
每次修改這個配置,須要去編譯 npm run buildgit
每次vue項目請求以 /api/開頭的路由自動轉換成 3000端口的服務github
nginx 配置 修改npm
vim vim /usr/local/nginx/conf/vhost/vx.itnote.cn.conf
location /api/ { proxy_pass http://127.0.0.1:3000/; # 當訪問v1的時候默認轉發到 3000端口 }
總體nginx 配置vim
server { listen 80; #listen [::]:80; server_name vx.itnote.cn ; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/vnshop/client/dist/; include none.conf; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } include enable-php.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location /api/ { proxy_pass http://127.0.0.1:3000/; # 當訪問api的時候默認轉發到 3000端口 } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log /home/wwwlogs/vx.itnote.cn.log; }