0

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")

Andi Hincu
  • 89
  • 5

2 Answers2

1

Any reference to other files (css, images, js, ...) in the index.html will be searched in directory "/var/www".


Exemple

  • index.html load a CSS file "css/file.css"
  • and your DocumentRoot is "/var/www"
  • Apache will look for "/var/www/css/file.css"

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.

Nic3500
  • 8,144
  • 10
  • 29
  • 40
  • So in my second example, if apache trys to load a css, it will go `/var/www/css/main.css` while loading the index from `/var/www/example.com/sometestfolder/main/wwwroot` ? – Andi Hincu Aug 25 '22 at 15:12
  • Found the issue, since its a blazor app, it loads the framework but if I acess an app in `/example.com/app`, apache will look for the framework in the `DocumentRoot`, correct path being DocumentRoot + /app if that makes sense. (apart from other 6 files that have the same problem) – Andi Hincu Aug 25 '22 at 15:22
  • For the record, to fix this: go to index.html, and modify `` to `` and every reference to a file will be relative to the index and not the `DocumentRoot`. – Andi Hincu Aug 25 '22 at 15:32
0

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