I have a project having angular 11 as a front end and Do.net Core 5 API.
I have to deploy my project in a Ubuntu 20.04 using apache2 web server.
Steps what I followed to deploy and configure the apache server.
Step1: I configured the Forward headers to handle the reverse proxy headers And in the next line If path is 404, redirecting to index.html page I used this because I want to deploy the application as a single unit deployment package Please refer to this link https://dzone.com/articles/publish-and-deploy-angular-and.net-core-applicatio
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor |
ForwardedHeaders.XForwardedProto
});
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404 && !System.IO.Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/index.html";
}
});
Step2: I installed apache2 server and installed required do.net packages Step3: Created a sample.service file in etc/systemd/system directory and enabled it.
systemctl enable sample.service
Step4: Created a sample.config file in etc/apache2/sites-available directory and enabled it.
a2ensite sample.conf
please refer this link https://www.syncfusion.com/blogs/post/hosting-multiple-asp.net-core-apps-in-ubuntu-linux-server-using-apache.aspx
and lastly restarted the apache server.
Everything seems to be working file but If a redirecting the url other than home I am getting 404. Typically url write issue.
If I open www.example.com - it works If I Open www.example.com/login - throwing 404
Later I created the .htaccess file and written url rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/api/.*$
RewriteRule . index.html [L]
</IfModule>
and enabled config file again and restarted the apache2 server
a2ensite sample.conf
But same issue occuring.
My file structure looks like
So I am confusing that where to place the .htaccess file to enable url rewrite rules. In the root application path like / or inside wwwroot folder.
Or Am I going with the wrong process. Please suggest me if its not a proper way of doing
Help me out with the other ways of doing so.
Many thanks in advance.
I simply put my sample.conf file in /etc/apache2/conf-enabled instead of sites-available. Then it worked
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.