I. Node project deployment process
Configure the deployment script file
Add the pM2 deployment script file file.json to the project root directory
{
"apps": [
"name": "movie".// Corresponds to the configuration on Nginx
"script": "app.js".// Import file
"env": {
"COMON_VARIABLE": "true"
},
"env_production": {
"NODE_ENV": "production"}]."deploy": {
"production": {
"user": "poetries".// Username on the Nginx server
"host": ["120.120.14.21"].// Server address
"port": "3922"."ref": "origin/master".// Pull code from the specified branch
"repo": "[email protected]:poetries/poetries.github.io.git"."path": "/www/movie/production".// Publish to the directory specified by the server
"ssh_options": "StrictHostKeyChecking=no".// Build in release
"post-deploy": "npm install --registry=https://registry.npm.taobao.org && grunt build && pm2 startOrRestart ecosystem.json --env production"."env": {
"NODE_ENV": "production"}}}}Copy the code
Configure the Nginx server
Create a new xx-3000.conf configuration file in vhost in the nginx installation directory
upstream movie { // website the directory name of the projectServer 127.0.0.1:3000; // Local boot entry on the server
}
/ / configuration server
server {
listen 80;
server_name movie.poetries.top; // The domain name pointing to
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://movie; // Corresponds to the directory above
proxy_redirect off;
}
// Process static resources
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|js|pdf|txt) {
root /www/movie/public; // Static resource path}}Copy the code
4. Enable the firewall
The setting of ubantu
- Open the
sudo vi /etc/iptables.up.rules
sudo iptables-restore /etc/iptables.up.rules
# movie
-A INPUT -s 127.0.0.1 -p tcp --destination-port 3001 -m state ESTABLISHED -j ACCEPT
-A OUTPUT -s 127.0.0.1 -p tcp --destination-port 3001 -m state ESTABLISHED -j ACCEPT
Copy the code
5. Deployment commands
pm2 deploy ecosystem.json production
The deployment ofpm2 deploy ecosystem.json production setup
Initialize the