先對項目生產(chǎn)環(huán)境build進(jìn)行設(shè)置:
# config index.js
build: {
env: require('./prod.env'),
port: 4343,
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
/**
* Source Maps
*/
productionSourceMap: false,
// https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}
nginx代理到node的配置:
server {
// listen 4343
server_name www.ygnili.com;
location / {
proxy_pass http://127.0.0.1:4343/; // 端口號和config目錄下index.js的build:{port:4343}一致
#proxy_cache proxycache;
#proxy_cache_key $host:$server_port$request_uri;
#proxy_cache_valid 200 304 1h;
proxy_pass_header Set-Cookie;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
#add_header X-Cache '$upstream_cache_status from $host';
}
}
有server_name的時候不能設(shè)置listen端口才顿,同理相反碉纺。
(操作只有把源碼請求的地址改了号胚,重新設(shè)置express跑的端口愉适,重新打包上傳服務(wù)器,啟動express栗竖,nginx代理過去)
express服務(wù)多個項目的時候暑脆,需要用到pm2去部署node,啟動express狐肢,把nginx轉(zhuǎn)發(fā)過來添吗,就ok了。