.net - 在 linux 和 apache 上的同一个 EC2 中运行多个 dotnet api 的项目

标签 .net linux apache amazon-web-services amazon-ec2

我有两个在 Linux EC2 AWS 实例上发布的 dotnet 项目,第一个项目在端口 5000 上,另一个在 50003 上。 我在第一个 conf.d 文件夹中创建了两个文件:

<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ErrorLog /var/log/httpd/hellomvc-error.log
CustomLog /var/log/httpd/hellomvc-access.log common

和另一个:

<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5003/
ProxyPassReverse / http://127.0.0.1:5003/
ErrorLog /var/log/httpd/hellomvc-error.log
CustomLog /var/log/httpd/hellomvc-access.log common

第二个只是一个 API。

我的问题是我可以毫无问题地在浏览器上打开第一个项目,但我无法访问第二个项目的 API,即使我可以使用 curl http://localhost:5003/api/Home 在本地访问它也是如此。

最佳答案

除非第一个项目和第二个项目有两个不同的域名,否则您可以尝试只使用一个 VirtualHost:

<VirtualHost *:80>
ProxyPreserveHost On

# send /api paths to project2
ProxyPass /api http://127.0.0.1:5003/api
ProxyPassReverse /api http://127.0.0.1:5003/api

# and everything else to project1
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/

ErrorLog /var/log/httpd/hellomvc-error.log
CustomLog /var/log/httpd/hellomvc-access.log common
</VirtualHost>

例如,如果您有两个使用 sam 路径 (/api) 的后端服务,您将必须使用不同的主机名和多个虚拟主机:

<VirtualHost *:80>
  ServerName project1.example.com

  ProxyPreserveHost On
  ProxyPass / http://127.0.0.1:5000/
  ProxyPassReverse /api http://127.0.0.1:5000/

  ErrorLog /var/log/httpd/project1-error.log
  CustomLog /var/log/httpd/project1-access.log common
</VirtualHost>

<VirtualHost *:80>
  ServerName api1.example.com

  ProxyPreserveHost On
  ProxyPass / http://127.0.0.1:5003/
  ProxyPassReverse /api http://127.0.0.1:5003/

  ErrorLog /var/log/httpd/api1-error.log
  CustomLog /var/log/httpd/api1-access.log common
</VirtualHost>

<VirtualHost *:80>
  ServerName api2.example.com

  ProxyPreserveHost On  
  ProxyPass / http://127.0.0.1:5004/
  ProxyPassReverse /api http://127.0.0.1:5004/

  ErrorLog /var/log/httpd/api2-error.log
  CustomLog /var/log/httpd/api2-access.log common
</VirtualHost>

当然,project1.example.com、api1.example.com 和 api2.example.com 需要解析到您服务器的 ip 地址

关于.net - 在 linux 和 apache 上的同一个 EC2 中运行多个 dotnet api 的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48484255/

相关文章:

linux - 在 bash 中解析文件夹名称

linux - 创建一个包含 2 列的文件,每列来自不同的文件

php - 通过命令行执行使用 ZendGuard 编码的 PHP 脚本

.net - 是否有 ECMA-335 CLI 规范的 HTML 版本?

c# - 使用 Compression.DeflateStream 压缩和解压缩 Stream

linux - 如何设置不在 bash 中执行的非交互式、非登录进程的路径

php - 自定义错误页面无法直接访问

php - Codeigniter http -> https 发现 302

c# - 你能解释一下这个 lambda 分组函数吗?

c# - C# 弱引用实际上是软引用吗?