good morning, I would like your help to solve this question I have about deploying ASPnet 5 (Core1, CoreCLR) on a subdomain. I have the following:
- Environment: GNU/Linux Apache MySQL PHP.
- DNV installed (.net core and mono)
- Yeoman generator.
By giving it "dnx web", it works for me at http://localhost:5000 I have this app under a folder in a subdomain: http://subdomain.domain.com/aspnet5/fx
How do I make the app work in that production environment? I have been recommended to make a docker container with nginx (+reverse proxy) and this weekend I will see this topic.
First I want to clarify that to "package" the application, prior to deployment, the command must be used
dnu publish
, to see the list of options you can use:dnu publish --help
.After packing, in the folder where the packing result is put (you can use the option
-o
to specify it) there will be a folderapproot
with a utilityweb
, this will be the one called from the server .It should be noted that it is possible to expose the application without the need for a reverse proxy. Kestrel boots on port 500x and changing it to port 80 would force root . You can, if you wish, use iptables to redirect requests to the kestrel process on port 500x, but this would bring down, I think, the server already dispatching on this port.
In addition to the above, Kestrel is not a production server and, as you noted in the question, it is recommended to use something like Apache or nginx. You say that at the moment you have Apache, I would think that it is possible to use it for this purpose but I have not seen it, I currently use nginx (without Docker, I have not needed it yet) for this.
What you need is to configure Apache as a Reverse Proxy so that requests made to the directory
aspnet5/fx
are redirected to your ASP.NET Core application.The steps to perform this configuration are as follows:
Install and enable Apache modules for Reverse Proxy
Modify your Apache website configuration to add the redirect (usually the file
000-default.conf
located in/etc/apache2/sites-enabled
)Configure the url
http://localhost:5000/aspnet5/fx/
in the ASP.NET Core app. This is done by adding in the filehosting.json
located at the root of the projectWhat I recommend is that you create another subdomain
aspnet5-fx.subdominio.dominio.com
that is the one that provides direct access to your ASP.NET Core application.In this case what you would have to do is:
sudo nano /etc/apache2/sites-available/001-aspnet.conf
)The content of this file would be the following
Lastly you have to enable the new website and reload the apache configuration
Something that is also important is that the files of your ASP.NET Core applications should not be located inside the Apache content directory , that is, in
/var/www/aspnet5/fx
, because doing dereverse proxy
is not necessary and if something fails in the configuration, they could end up in access code files. The recommended thing would be to locate ourselves, for example, in/opt/aspnet5/fx