I have a WebServer (CentOS) with Apache, it has a a Blazor WASP app, if the DocumentRoot
is set directly where the index.html is, the app works, but if it isn’t, it will read the index.html and show the loading screen but wont load. To clarify:
Blazor app location: /var/www/sometestfolder/main/wwwroot
WORKS
- httpd.conf:
DocumentRoot "/var/www/sometestfolder/main/wwwroot"
- Site accessed via:
example.com
DOESN’T WORK:
- httpd.conf:
DocumentRoot "/var/www"
- Site accessed via:
example.com/sometestfolder/main/wwwroot
(shows the "Loading… An unhandled error has occurred. Reload 🗙 " text of a blazor app but soesnt seem to be loaded as one since "An unhandled error has occurred" shouldn’t be there.
QUESTION : Why doesn’t the second case work? Is there a way for it to work or am I doing everything wrong?
I dont think I’m publishing the app correctly (ftp publish to the server, result being wwwroot folder and web.config file) and that leads to the app working witohut the need of any virtual host, microsoft manual states that a blazor app needs this virtual host to work:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias *.example.com
DocumentRoot "/var/www/blazorapp"
ErrorDocument 404 /index.html
AddType application/wasm .wasm
AddType application/octet-stream .dll
<Directory "/var/www/blazorapp">
Options -Indexes
AllowOverride None
</Directory>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/octet-stream
AddOutputFilterByType DEFLATE application/wasm
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
ErrorLog /var/log/httpd/blazorapp-error.log
CustomLog /var/log/httpd/blazorapp-access.log common
source: https://learn.microsoft.com/es-es/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-6.0
(Scroll down do "Apache")
2
Answers
Any reference to other files (css, images, js, …) in the index.html will be searched in directory "/var/www".
Exemple
DocumentRoot
defines the "virtual /" or the root of your web site files.I would expect errors in your logs (Apache or application) indicating that it cannot find the files. You might need to increase logging (LogLevel) to get more details.
if index.html and the associated files/ folders are not located at the document root it won’t work. What I did to get it to work is here Blazor WASM on Apache is not able to find my API endpoints at all
I did try setting
<base href="" />
, but it didn’t work for me. Probably because I have multiple entry points into the app, and want consistent addressing across the whole website