更新时间:2022-11-06 20:31:36
您可以添加一个反向代理来做到这一点.假设您的ASP.NET Core
应用通过以下方式在http://127.0.0.1:5000/
上运行:
You could add a reverse proxy to do that. Let's say your ASP.NET Core
app runs on http://127.0.0.1:5000/
by:
dotnet run --urls=http://localhost:5000
如果请求以http://somedomain.com/v2/
开头,则代理到ASP.NET Core App
.
if the request start with http://somedomain.com/v2/
, then proxy to the ASP.NET Core App
.
+-------+
| +----------------------------------------+
| | |
| | PHP module |
| | |
| +----------------------------------------+
|Apache2|
| |
| (80) | +--------------------+
| | start with /v2/ | |
| | | Asp.Net Core App |
| +-------------------> |
| | | (5000) |
| | reverse proxy | |
+-------+ +--------------------+
首先,通过在httpd.conf
中取消注释这些行来配置代理模块:
Firstly, configure proxy module by uncomment these lines in httpd.conf
:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_http2_module modules/mod_proxy_http2.so
然后为以/v2/
开头的请求添加以下反向代理设置:
And then add the following reverse proxy settings for requests that start with /v2/
:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /v2/ http://127.0.0.1:5000/
ProxyPassReverse / http://somedomain.com/
ServerName somedomain.com
ErrorLog ${APACHE_LOG_DIR}webapp1-error.log
CustomLog ${APACHE_LOG_DIR}webapp1-access.log common
</VirtualHost>
现在它应该可以正常工作了.
Now it should work as expected.
有效的演示
这是一个在8089
而不是80
上监听的演示:
Here's a demo that listens on 8089
instead of 80
: