簡體   English   中英

在Linux和apache的同一EC2中運行多個dotnet api的項目

[英]Run multiple dotnet api's project in the same EC2 on linux and apache

我有兩個在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。

我的問題是我可以在瀏覽器中打開第一個項目,沒有任何問題,但是即使使用curl http:// localhost:5003 / api / Home也可以在本地訪問它,但我無法訪問第二個項目的API

除非您為第一個項目和第二個項目有兩個不同的域名,否則您可以嘗試僅使用一個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地址

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM