Nginx配置SSR客户端和API服务器

brtdzjyr  于 2023-05-16  发布在  Nginx
关注(0)|答案(1)|浏览(184)

我遇到了一个Nginx站点可用配置文件的问题。我正在尝试设置一个使用服务器端渲染(SSR)和Nodejs的客户端,以及使用Ruby on Rails的RestfulAPI。我想要的是我的默认路径位置“/”,它指向Nodejs服务器,我还希望所有对我的服务器(我的API)的调用都指向路径位置“/api”。
下面是我的配置文件:

listen 80;
server_name didsomeonesayfrankerz.com;

passenger_friendly_error_pages on;
passenger_enabled on;
passenger_app_group_name didsomeonesayfrankerz;
passenger_min_instances 15;
passenger_max_request_queue_size 200;
passenger_app_env production;
client_max_body_size 10M;

# API server
location /api {
  passenger_app_type ruby;
  passenger_ruby /home/ost/.rvm/gems/ruby-3.0.0/wrappers/ruby;
  root /home/ost/didsomeonesayfrankerz/server/public;
}

# SSR
location / {
  root /home/ost/didsomeonesayfrankerz/client/dist/ssr;
  passenger_app_type node;
  passenger_nodejs /home/ost/.nvm/v18.16.0;
  passenger_startup_file /home/ost/didsomeonesayfrankerz/client/dist/ssr/index.js;
}

charset utf-8;

location ~ /\.(?!well-known).* {
  deny all;
}

我的问题很简单:我对服务器(“/API”)的每个调用都被节点服务器(SSR)捕获。我试着使用“location ^~ /API”,但没有工作。
任何帮助或建议都很感激!

bnl4lu3b

bnl4lu3b1#

我终于发现了问题:passenger_app_group_name。简单地评论它,一切都很好。也可以将passenger_app_group_name放在每个位置点内。

listen 80;
server_name didsomeonesayfrankerz.com;

passenger_friendly_error_pages on;
passenger_enabled on;
# passenger_app_group_name didsomeonesayfrankerz;
passenger_min_instances 15;
passenger_max_request_queue_size 200;
passenger_app_env production;
client_max_body_size 10M;

# API server
location /api {
  passenger_app_type ruby;
  passenger_ruby /home/ost/.rvm/gems/ruby-3.0.0/wrappers/ruby;
  root /home/ost/didsomeonesayfrankerz/server/public;
  passenger_app_group_name didsomeonesayfrankerzAPI;
}

# SSR
location / {
  root /home/ost/didsomeonesayfrankerz/client/dist/ssr;
  passenger_app_type node;
  passenger_nodejs /home/ost/.nvm/v18.16.0;
  passenger_startup_file /home/ost/didsomeonesayfrankerz/client/dist/ssr/index.js;
  passenger_app_group_name didsomeonesayfrankerzSSR;
}

charset utf-8;

location ~ /\.(?!well-known).* {
  deny all;
}

相关问题