gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:17:41 24 4
gpt4 key购买 nike

我有两个在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com