如何解决使用 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) {}
}
};
"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 时,结果总是返回:
无法获取/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。