使用 pm2 和 nginx

问题描述

我有一个域,它为多个具有不同编程语言的应用程序提供服务。 所以当我们通过浏览器访问应用的时候,URL应该是:

mydomain.org/app-name

我需要关于如何在子目录中部署我的 NUXT SSR 应用程序的帮助。

这是我的 Nginx 配置:

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

server {
  #listen   80;
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name  mydomain.org;

  if ($scheme = "http") {
       return 301 mydomain.org$request_uri;
  }
  # note that these lines are originally from the "location /" block
  root   /usr/share/Nginx/html;
  index index.PHP index.html index.htm main.js server.js;

  charset utf-8;

  location /app-one/ {
    try_files $uri $uri/ /app-one/index.PHP?$args;
  }

  location /app-two/ {
    try_files $uri $uri/ /app-two/index.PHP?$args;
  }

  #here is my nuxt app
  location /nuxt-app/ {
       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://publicIPAddress:3015/;
  }

下面是我的nuxt.config.js

const pkg = require("./package");

const VuetifyLoaderPlugin = require("vuetify-loader/lib/plugin");
import axios from "axios";

module.exports = {
  server: {
    port: 3015
  },router: {
    base: "/payroll-staging/",// prefetchLinks: true
  },/*
  ** Build configuration
  */
  build: {
    transpile: ["vuetify/lib"],plugins: [new VuetifyLoaderPlugin()],loaders: {
      stylus: {
        import: ["~assets/style/variables.styl"]
      }
    },extractCSS: true,optimization: {
       splitChunks: {
         cacheGroups: {
           styles: {
             name: 'styles',test: /\.(css|vue)$/,chunks: 'all',enforce: true
           }
         }
       }
    },/*
    ** You can extend webpack config here
    */
    extend(config,ctx) {}
  }
};

我还在 package.json 文件中设置了此代码

"config": {
  "nuxt": {
    "host": "0.0.0.0","port": "3015"
  }
}

我已经尝试过使用 ecosystem.config.js 文件

module.exports = {
  apps: [
    {
       name: 'app-name',exec_mode: 'cluster',instances: 'max',// Or a number of instances
       script: './node_modules/nuxt/bin/nuxt.js',args: 'start'
    }
  ]
}

之后我运行:

% npm run build
% pm2 start

但是当我尝试访问应用程序 URL 时,结果总是返回:

无法获取/

failed load

有人可以帮我解决这个问题吗? 也许我错过了另一个步骤?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)