In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to publish and deploy Asp.Net Core in MacOS+Linux+Nginx". In daily operation, I believe many people have doubts about how to publish and deploy Asp.Net Core in MacOS+Linux+Nginx. Xiaobian consulted all kinds of information and sorted out simple and easy to use operation methods. I hope to answer your doubts about "how to publish and deploy Asp.Net Core in MacOS+Linux+Nginx"! Next, please follow the small series to learn together!
Create a new WebApp project
In the Asp.Net Core project, we create a new empty Web application using the dotnet new -t WebApp command and.
Here is a screenshot of me on Mac:
Mainly by using the following commands:
mkdir HelloWebApp This command creates a folder called HelloWebApp.
dotnet new -t Web This command uses Web templates to create a WebApp Mvc application.
After creating our new application, test our application using the dotnet restore and dotnet run commands.
You can see it's already running successfully.
Let's open up the browser and type http://localhost:5000 to see how it works.
ps: Safari below, the browser address bar does not see the port number, it is actually port 5000.
Posted to Linux, Mac OS
If we publish the application, we need to use the dotnet publish command. You can see some command parameters that can be used by using the--help parameter.
-f|--framework Target framework to compile for -r|--runtime Target runtime to publish for -b|--build-base-path Directory in which to place temporary outputs -o|--output Path in which to publish the app --version-suffix Defines what `*` should be replaced with in version field in project.json -c|--configuration Configuration under which to build --native-subdirectory Temporary mechanism to include subdirectories from native assets of dependency packages in output --no-build Do not build projects before publishing
We run dotnet publish directly using the default publishing path. When we see Published 1/1 projects successfully, it means that we have published successfully. Then go to the netcore app1.0 folder under the Debug folder under the bin folder and you will see a publish folder. This is the folder generated by the default release, where you can see all the assembly files that our program depends on.
It is necessary to explain the subfolders in the publish folder after publishing.
appsettiong.json application configuration file refs application reference. Net fx system assembly runtimes runtime environment, you can see that the folder contains win7, linxu, mac os, etc., indicating that our application is cross-platform. The views folder holds our mvc view files. The wwwroot folder stores js libraries, css stylesheets, and images used by the front-end.
Then we switch the working directory to the publish folder. Use dotnet HelloWebApp.dll to test whether the program works properly after release.
Reverse Proxy with Nginx
Mac OS
Linux(Ubuntu)
precautions
Reverse proxy, that is, part of the path of our application to Nginx to process, such as static files, images, etc. The other part of the dynamic is left to Kestrel to handle. This reduces the stress on our backend Kestrel, as well as configuring Load Balancer etc. in Nginx.
Another important advantage is that caching in the Web is handled at the proxy server level. Look at this picture below:
Mac OS
To install dotnet environment, see the official website https://www.microsoft.com/net/core.
1. Open the command line in mac and enter brew install nginx to install nginx first.
After the installation is complete, enter nginx -v to see if the installation is successful. nginx version: nginx/1.10.1 indicates that the installation was successful.
3. Configure nginx proxy.
After installing nginx, the default configuration file path is in the/usr/local/etc/nginx folder. Find the nginx.conf configuration file in this folder, open it with Visual Studio Code, find the location node that listens on port 80 in the Server node, and modify the configuration as follows:
location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }
Save and exit. Then reload the configuration using the sudo nginx -s reload command.
Then we opened the browser and typed http://localhost, and found that we had already accessed our site through nginx.
ps: Safari below, the browser address bar does not see the port number, it is actually port 80.
Linux(Ubuntu)
To install dotnet environment, see the official website https://www.microsoft.com/net/core.
First create a new folder in Ubuntu and copy our publish folder to Liunx. Then test whether it works properly.
1. Open a new command line window in Linux (Ubuntu) and enter apt-get install nginx to install nginx first.
After the installation is complete, enter nginx -v to see if the installation is successful. Nginx version: nginx/1.4.6 indicates that the installation has been successful.
yxd@ubuntu:~$ sudo nginx -vnginx version: nginx/1.4.6 (Ubuntu)
Test whether nginx runs successfully. Open your browser and enter http://localhost to see if the following interface is displayed.
3. Configure nginx proxy.
After installing nginx, the default configuration file path is in/etc/nginx/sites-available/default. Change the working directory to/etc/nginx/sites-available/and use sudo gedit default to open the default file. In the Server node, find the location node that listens on port 80, and modify the content as follows:
server { listen 80; #root /usr/share/nginx/html; #index index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }}
Save and exit. Then reload the configuration using the sudo nginx -s reload command.
Then we opened the browser and typed http://localhost, and found that we had already accessed our site through nginx.
precautions
When using the nginx proxy to access the site, the command line window that holds the command dotnet run HelloWebApp.dll must be open.
You can use the following command to make a command line run in the background process.
nohup dotnet HelloWebApp.dll &
At this point you can close the command line window.
At this point, the study on "how to publish and deploy Asp.Net Core in MacOS+Linux+Nginx" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.