修改apache的配置文件,多个域名解析到同一个服务器上,使用apache做代理,通过域名将请求转发到不同的端口,可以为每个网站构建一个配置文件,放置在conf.d文件夹下面,比如:

//example1.conf
<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
    ServerName example1.com
    ServerAlias *.example1.com
    ErrorLog logs/example1-error.log
    CustomLog logs/example1-access.log common
</VirtualHost>
//example2.conf
<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5555/
    ProxyPassReverse / http://127.0.0.1:5555/
    ServerName example2.com
    ServerAlias *.example2.com
    ErrorLog logs/example2-error.log
    CustomLog logs/example2-access.log common
</VirtualHost>

域名解析,example1.com,example2.com都解析到当前的服务器上即可。

配置完成之后,重启httpd服务。

service httpd restart

启动.net服务,可以直接运行服务,也可以使用docker。

dotnet project.dll

或者在/etc/systemd/system路径下创建一个服务文件,比如:example.service,可对服务进行监视。

[Unit]
Description=Example .NET Web API App running on CentOS 7

[Service]
WorkingDirectory=/home/ToolApp/bin/Release/net6.0/publish
ExecStart=/usr/bin/dotnet /home/example/bin/Release/net6.0/publish/example.dll

[Install]
WantedBy=multi-user.target

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注