Hey, I have a react website on my domain
But the routes are returning 404 (example.com/test)
I managed to fix this by editing the local.conf file
But every once in a while the file gets reset
Is there anything I can do to fix this?
No need to edit the config file. Add a record on the System | Custom DNS tab of the admin panel. Point the www sub-domain to the address where you website is hosted. MIAB will automatically take care of the DNS records for you.
This is assuming you are not using an external DNS, when you would need to update the record there of course.
Rereading your post. Perhaps you are hosting the website on MIAB. In that case, you need to see the directions on the Web tab of the admin panel. There you can see where you need to store the static files, e.g.
/home/user-data/www/default
Yes I am hosting the website on MIAB and my website files are in “/home/user-data/www/default”
But since I have a react website anything other then the index page is returning 404 error
OK. Static websites only though.
React requires Java doesn’t it? Not sure you can do this with MIAB but I’m no expert on this.
I also don’t know anything about React. Several tutorials I find when searching state to use tools on the server such as NodeJS, which MiaB is not configured to support.
Unless you are just serving static files to your users that don’t have any requirement to communicate back to the server, the files should function as expected. If you are getting 404
responses, check the access and error logs.
I am just serving static files.
A react project consists of just one main index html file.
And all paths lead to this file.
(For example in a react website: domain.com/test > index.html
And in a normal website: domain.com/test > test/index.html)
I have added this line: “error_page 404 /index.html;” to local.conf which fixes it but the local.conf file gets reset every once in a while so I am not sure what to do.
I have done nothing with trying to serve anything other than postcard sites for proof of work purposes with MiaB.
However, there is this custom.yaml
hidden feature for /home/user-data/www/
that many use. It seems somewhat undocumented, so I’m not sure how it’s employed.
Also, nginx.conf
has include /etc/nginx/conf.d/*.conf;
, so you could possible put your own .conf
file in there and see what happens.
I serve a couple of sites for different domains from my box. Only static html.
I seem to remember I had to select (change?) some options on the web tab of admin but I don’t quite recall as that was some time back.
Have you tried any settings on that tab?
Yeah, I just went there to refresh my memory and there are instructions plus an automated tool which will change the default directory for a domain from /default/
to /example.com/
or /www.example.com/
, etc.
React is just a JS UI library. It can interface with NodeJS but I don’t believe it is entirely required to use it.
I have used static sites with Jekyll and Vitejs and they seem to work without any config beyond the path setting
If you need all requests to be handled by one file, this will likely require an nginx config change, which is unsupported by Mail-in-a-Box and reverted on each update.