我正在使用 IONOS linux vps 和 Plesk Obsidian 来托管我的项目。我使用 .NetCore 创建后端 api 并使用 React 作为前端。
后端部署完美,我使用 apache2 为后端提供服务。我可以调用我的 api,https://www.mywebsite.com/api/controller
但我正在努力进行反应部署。(事件虽然它应该更容易)
我尝试了什么:
一些教程推荐的最简单的方法,将
build
文件夹内容复制到httpdocs
文件夹(在 Plesk 中默认设置为文档根目录)我还尝试将构建文件放入
/var/www/vhosts/default/htdocs
(在使用 https 之前工作)并将配置包含在apache2.conf
文件中:<VirtualHost *:443> ServerName www.mywebsite.com DocumentRoot /var/www/vhosts/default/htdocs/ # Relax Apache security settings <Directory /var/www/vhosts/default/htdocs> Allow from all Options -MultiViews Require all granted </Directory>
sites-enabled
我还尝试在文件夹中的单独文件中指定配置。
以上所有内容都产生相同的结果:当我调用https://www.mywebsite.com/index.html
或存在同一文件夹中的静态文件时,https://www.mywebsite.com/pic.png
我总是得到404
并且请求失败。
http
奇怪的是,在我从 更改为之前它工作正常https
。
.netcore 的配置: http:
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ServerName mywebsite.com
ServerAlias *.mywebsite.com
ErrorLog ${APACHE_LOG_DIR}error.log
CustomLog ${APACHE_LOG_DIR}access.log common
HTTPS:
SSLProxyEngine on
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
ProxyPreserveHost On
ProxyPass / https://127.0.0.1:5001/
ProxyPassReverse / https://127.0.0.1:5001/
ServerName mywebsite.com
ServerAlias *.mywebsite.com
ErrorLog ${APACHE_LOG_DIR}error.log
CustomLog ${APACHE_LOG_DIR}access.log common
和服务文件:
[Unit]
Description=Example .NET Web API App running on UBUNTU
[Service]
WorkingDirectory= /var/www/vhosts/mywebsite.com/publish
ExecStart=dotnet /var/www/vhosts/mywebsite.com/publish/API.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=my-web
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
我还尝试将前端文件移动到发布文件夹,但似乎没有任何效果。
任何人都知道我应该尝试解决这个问题吗?