Nginx 、pm2整理

原创
2020/03/18 10:07
阅读数 897

常用命令

nginx
nginx -s reload

目录

  • /etc/nginx/sites-available 存放网站配置链接
  • sites-enabled 存放网站配置
  • ln -s /etc/nginx/sites-available/education /etc/nginx/sites-enabled/education 生成链接
  • /etc/nginx/cert 存放证书(自定义)

配置

# http 跳转到 https
server {
  listen 80;
  server_name edu.qushen.net;
  rewrite ^(.*)$ https://$host$1 permanent;
}

server {
  listen 80;
  server_name admin.edu.qushen.net;
  rewrite ^(.*)$ https://$host$1 permanent;
}

# 以下属性中以ssl开头的属性代表与证书配置有关,其他属性请根据自己的需要进行配置。
server {
  listen 443 ssl; #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
  server_name edu.qushen.net; #将localhost修改为您证书绑定的域名,例如:www.example.com。
  ssl_certificate cert/education/3541609_edu.qushen.net.pem; #将domain name.pem替换成您证书的文件名。
  ssl_certificate_key cert/education/3541609_edu.qushen.net.key; #将domain name.key替换成您证书的密钥文件名。
  ssl_session_timeout 5m;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件。
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用该协议进行配置。
  ssl_prefer_server_ciphers on;

  location / {
    root /var/www/education/web/dist;
    try_files $uri $uri/ /index.html;
  }
}

server {
  listen 443 ssl; #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
  server_name admin.edu.qushen.net; #将localhost修改为您证书绑定的域名,例如:www.example.com。
  ssl_certificate cert/education/3612755_admin.edu.qushen.net.pem; #将domain name.pem替换成您证书的文件名。
  ssl_certificate_key cert/education/3612755_admin.edu.qushen.net.key; #将domain name.key替换成您证书的密钥文件名。
  ssl_session_timeout 5m;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件。
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用该协议进行配置。
  ssl_prefer_server_ciphers on;

  location / {
    root /var/www/education/frontend/dist;
    try_files $uri $uri/ /index.html;
  }
}


server {
  listen 443 ssl; #SSL协议访问端口号为443。此处如未添加ssl,可能会造成Nginx无法启动。
  server_name api.edu.qushen.net; #将localhost修改为您证书绑定的域名,例如:www.example.com。
  ssl_certificate cert/education/3543472_api.edu.qushen.net.pem; #将domain name.pem替换成您证书的文件名。
  ssl_certificate_key cert/education/3543472_api.edu.qushen.net.key; #将domain name.key替换成您证书的密钥文件名。
  ssl_session_timeout 5m;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #使用此加密套件。
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用该协议进行配置。
  ssl_prefer_server_ciphers on;

  location / {
    proxy_pass http://127.0.0.1:7001;
  }
}

Vue项目配置子目录

修改路由index.js:

修改vue.config.js:

部署文件夹按照子目录结构创建,如:

注意二级目录写法,比如下面的client

server {
  listen 80;
  server_name gaoduanjiyou.audihd.net;

  location / {
    root /var/www/new_write_off_system/client/agent;
    try_files $uri $uri/ /index.html;
  }
  location /h5/ {
    root /var/www/new_write_off_system/client/;
    try_files $uri $uri/ /h5/index.html;
  }
  
  location /admin/ {
    root /var/www/new_write_off_system/frontend/;
    try_files $uri $uri/ /admin/index.html;
  }

  location /backend/ {
    proxy_pass http://127.0.0.1:7002/;
    proxy_set_header Host $host:$server_port;
  }
}


Nuxt.js 项目+Vue项目+Egg.js项目

map $sent_http_content_type $expires {
  "text/html" epoch;
  "text/html; charset=utf-8" epoch;
  default off;
}

server {
  listen 80;
  server_name game.qushen.net;

  gzip on;
  gzip_types text/plain application/xml text/css application/javascript;
  gzip_min_length 1000;

  location / {
    expires $expires;

    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_read_timeout 1m;
    proxy_connect_timeout 1m;
    proxy_pass http://127.0.0.1:3000; # set the address of the Node.js instance here
  }

  location /admin {
    root /var/www/game/frontend/;
    try_files $uri $uri/ /admin/index.html;
  }

  location /backend/ {
    proxy_pass http://127.0.0.1:7003/;
    proxy_set_header Host $host:$server_port;
  }
}

pm2 启动 nuxt 项目

cd 到项目目录下(注意:--name 没有空格)

  • pm2 start npm --name "game" -- run start
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部