Apache(Linux) + ASP.NET Core(kestrel) の構築
July 6, 2025 6:19(1) Apache をインストールする
yum update -y
yum -y install httpd mod_ssl
(2) Apache の構成ファイルを追加
/etc/httpd/conf.modules.d/hoge-app.conf
※以下の例では3の ASP.NET Core サイトをポート番号別に設定している。
別途ポート開放が必要なので、CentOS 7 ファイアウォールの設定を参照
<VirtualHost *:*>
RequestHeader set "X-Forwarded-Proto" expr=https
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /manual !
ProxyPass /notification !
ProxyPass / http://127.0.0.1:5001/
ProxyPassReverse / http://127.0.0.1:5001/
</VirtualHost>
<VirtualHost *:8080>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
</VirtualHost>
<VirtualHost *:8081>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5002/
ProxyPassReverse / http://127.0.0.1:5002/
</VirtualHost>
apache の起動
service httpd configtest
systemctl restart httpd
(3) ASP.NET Core(kestrel)サービスを作成
サービス用のファイルを作成
/etc/systemd/system/kestrel-hoge-management.service
[Unit]
Description=Example .NET Web API App running on CentOS 7
[Service]
WorkingDirectory=/home/hoge/hoge00/app/Web/Hoge.Web.Management
ExecStart=/home/hoge/hoge00/app/Web/Hoge.Web.Management/Hoge.Web.Management
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=hoge00
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
※ Environment=ASPNETCORE_ENVIRONMENT=Production が環境変数設定値 (appconfig[.Environment].jsonの参照先)となる
サービスの起動
systemctl enable kestrel-hoge-management.service
systemctl start kestrel-hoge-management.service
systemctl status kestrel-hoge-management.service