﻿{"id":315,"date":"2022-12-30T09:51:54","date_gmt":"2022-12-30T01:51:54","guid":{"rendered":"https:\/\/simon.ice.com.tw\/?p=315"},"modified":"2022-12-31T09:47:55","modified_gmt":"2022-12-31T01:47:55","slug":"debian-%e9%83%a8%e7%bd%b2-asp-net-core","status":"publish","type":"post","link":"https:\/\/old.ice.com.tw\/?p=315","title":{"rendered":"Debian \u90e8\u7f72 ASP.NET Core"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">1.<a rel=\"noreferrer noopener\" href=\"https:\/\/learn.microsoft.com\/zh-tw\/dotnet\/core\/install\/linux?WT.mc_id=dotnet-35129-website\" target=\"_blank\">\u5b89\u88dd NET 7 Runtime<\/a><br>   \u67e5\u770b\u5df2\u5b89\u88dd\u7684\u7248\u672c  <code>dotnet --list-runtimes<\/code><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2.\u5b89\u88dd Apache server<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache server will act as a reverse proxy and pass the request to the <a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/fundamentals\/servers\/kestrel?view=aspnetcore-5.0\" target=\"_blank\" rel=\"noreferrer noopener\">Kestrel Server<\/a> from the internet.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2_1. Let\u2019s install the <a rel=\"noreferrer noopener\" href=\"https:\/\/httpd.apache.org\/\" target=\"_blank\">Apache server<\/a> in the Linux machine using the following command:<br><code>sudo apt install apache2<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2_2.After installing the Apache Server, install the following required modules:<br><code>sudo a2enmod rewrite<br>sudo a2enmod proxy<br>sudo a2enmod proxy_http<br>sudo a2enmod headers<br>sudo a2enmod ssl<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2_3.Now, restart the Apache server using the following command:<br><code>sudo systemctl restart<\/code> <code>apache2<\/code><\/p>\n<cite><br>3.\u4e0a\u50b3\u7db2\u7ad9\u5167\u5bb9\u5230\u670d\u52d9\u5668.<br><br><br><br>4. \u70ba\u7db2\u7ad9\u5efa\u7acb\u4e00\u500b\u670d\u52d9\u6a94\u6848<br>     #sudo nano \/<strong>etc\/systemd\/system\/<\/strong>xxx.ice.com.tw<strong>.service<\/strong><br>     <br><code>[Unit]<br>Description=Running ASP.NET Core on debian 11 Webserver APACHE<br>[Service]<br>WorkingDirectory=\/sftserver\/web\/xxx.ice.com.tw\/<br>ExecStart=\/usr\/bin\/dotnet \/sftpserver\/web\/xxx.ice.com.tw<\/code>\/xxx.<code>dll<br>Restart=always<br># Restart service after 10 seconds if the dotnet service crashes<br>RestartSec=10<br>KillSignal=SIGINT<br>SyslogIdentifier=dotnet-example<br>User=www-data<br>Environment=ASPNETCORE_ENVIRONMENT=Production<br>Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false<br>[Install]<br>WantedBy=multi-user.target<\/code><br><br>In the above configuration,<br><strong>WorkingDirectory<\/strong> defines the folder from which the service will run.<br><strong>ExecStart<\/strong> defines the application to be started in this service.<br>Then, move the newly created file to the Linux server in the location <strong>etc\/systemd\/system\/<\/strong> using FileZilla. Enable and start the service using the following command in PuTTY:<br><code>sudo systemctl enable <code>xxx.ice.com.tw<\/code>.service<br>sudo systemctl start <code>xxx.ice.com.tw<\/code>.service<\/code><br><br>5. \u5efa\u7acbApach\u7d44\u614b\u6a94\u6848<br>    #sudo nano \/<strong>etc\/apache2\/sites-available<\/strong>\/<code><code>xxx.ice.com.tw<\/code><\/code>.conf<br>figuration file<br>Create a new host configuration file named <strong>sample.conf<\/strong> and add the following configuration to it:<br><code>&lt;VirtualHost *:80&gt;<br>ServerName <code><code>xxx.ice.com.tw<\/code><\/code><br>ProxyPreserveHost On<br>ProxyPass \/ http:\/\/127.0.0.1:5000\/<br>ProxyPassReverse \/ http:\/\/127.0.0.1:5000\/<br>ErrorLog ${APACHE_LOG_DIR}\/<code><code>xxx.ice.com.tw<\/code><\/code>.-error.log<br>&lt;\/VirtualHost&gt;<\/code><br>In the above configuration:<br><strong>VirtualHost *:80<\/strong>&nbsp;means that the site is hosted under port 80.<br>Domain URL is given in the <strong>ServerName<\/strong>.<br>For <strong>proxypass<\/strong> and <strong>proxypassreverse<\/strong>, we have provided the Kestrel server that is running locally and its default port is 5000.<br>All the application\u2019s config files are located in the file path <strong>etc\/apache2\/sites-available<\/strong> in the Linux server. So, move the created config file to the Linux server under this folder.<br>Now, enable the new site configuration using the following command:<br>#sudo a2ensite xxx.ice.com.tw.conf<br><br>Check the syntax of the configuration using the following command:<br><code>sudo apachectl configtest<\/code><br>If there is no error, then your site is ready to go!<br>5. \u5efa\u7acb\u7b2c2\u500b\u4ee5\u5f8cASP.NET Core \u7db2\u7ad9<br>We have seen how to create a service and config file to host an ASP.NET Core application in a Linux server.&nbsp;Now, let\u2019s see how you can host another application on the same Linux server. To do so, follow these steps:<br>Move the new application sample to the Linux server under the file path <strong>\/var\/www\/sample1<\/strong>.<br>Then, create a new service file named&nbsp; <strong>sample1.service<\/strong> and add the following configuration to it. Here, we will add the port from which the new sample application will be hosted.<br><code>[Unit]<br>Description=Running ASP.NET Core on Ubuntu 18.04 Webserver APACHE<br>[Service]<br>WorkingDirectory=\/var\/www\/sample\/<br>ExecStart=\/usr\/bin\/dotnet \/var\/www\/sample\/sample.dll<br>Restart=always<br># Restart service after 10 seconds if the dotnet service crashes:<br>RestartSec=10<br>KillSignal=SIGINT<br>SyslogIdentifier=dotnet-example<br>User=www-data<br>Environment=ASPNETCORE_ENVIRONMENT=Production<br>Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false<br>Environment=ASPNETCORE_URLS=http:\/\/127.0.0.1:5001<br>[Install]<br>WantedBy=multi-user.target<\/code><br>Move the service and enable it by following the steps given in the <a rel=\"noreferrer noopener\" href=\"https:\/\/www.syncfusion.com\/blogs\/post\/hosting-multiple-asp-net-core-apps-in-ubuntu-linux-server-using-apache.aspx#create-a-servecie-to-run-the-application\" target=\"_blank\">Create a service to Run the application section<\/a>.<br>Now, create a new host configuration file named <strong>sample1.conf<\/strong> and add the following command to it. Here, for proxy, use the new port 5001.<br><code>&lt;ltVirtualHost *:80&gt;<br>ServerName www.sample1.com<br>ProxyPreserveHost On<br>ProxyPass \/ http:\/\/ 127.0.0.1:5001\/<br>ProxyPassReverse \/ http:\/\/ 127.0.0.1:5001\/<br>ErrorLog ${APACHE_LOG_DIR}\/sample-error.log<br>&lt;\/VirtualHost&gt;<\/code><br>Finally, move the .conf file to the Linux server and then enable the site. Now, you can access the new hosted application.<br><strong>Note:&nbsp;<\/strong>Similarly, you can host any number of applications using the app\u2019s port in the Linux server.<br>Conclusion<br>Thanks for reading! In this blog post, we have seen how to host multiple ASP.NET Core applications in a Linux Ubuntu server using Apache as a reverse proxy. With this approach, hosting an ASP.NET Core app in Linux isn\u2019t complicated. So, try out the steps provided in this blog post and leave your feedback in the comments section.<br>The Syncfusion <a rel=\"noreferrer noopener\" href=\"https:\/\/www.syncfusion.com\/aspnet-core-ui-controls\" target=\"_blank\">ASP.NET Core UI controls<\/a> library powered by <a rel=\"noreferrer noopener\" href=\"https:\/\/www.syncfusion.com\/javascript-ui-controls\" target=\"_blank\">Essential JS 2<\/a> is the only suite that you will ever need to build an application since it contains over 70 high-performance, lightweight, modular, and responsive UI controls in a single package. Use them to increase your productivity in app development!<br>If you\u2019re already a Syncfusion user, you can download the <a rel=\"noreferrer noopener\" href=\"https:\/\/www.syncfusion.com\/account\/downloads\/studio\/\" target=\"_blank\">product setup<\/a>,&nbsp;or, you can download a free&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.syncfusion.com\/account\/downloads\/studio\" target=\"_blank\">30-day trial&nbsp;<\/a>to evaluate our products.<br>You can also contact us through our&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.syncfusion.com\/forums\" target=\"_blank\">support forum<\/a>,&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.syncfusion.com\/account\/login\" target=\"_blank\">Direct-Trac<\/a>,&nbsp;or&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.syncfusion.com\/feedback\/\" target=\"_blank\">feedback portal<\/a>. As always, we are happy to assist you!<\/cite><\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/docs.devexpress.com\/XtraReports\/401730\/web-reporting\/asp-net-core-reporting\/use-the-devexpress-cross-platform-drawing-engine\" target=\"_blank\" rel=\"noreferrer noopener\">Use the DevExpress Cross-Platform Drawing Engine<\/a><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>1.\u5b89\u88dd NET 7 Runtime \u67e5\u770b\u5df2\u5b89\u88dd\u7684\u7248\u672c dotnet --list-runtimes 2.\u5b89\u88dd &hellip; <a href=\"https:\/\/old.ice.com.tw\/?p=315\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008Debian \u90e8\u7f72 ASP.NET Core\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=315"}],"version-history":[{"count":13,"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":333,"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions\/333"}],"wp:attachment":[{"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/old.ice.com.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}