Developing blog project based on ABP vNext and. Net core

Time:2020-12-2

Series of articles

  1. Developing blog project based on ABP vNext and. Net core
  2. Developing blog project based on ABP vNext and. Net core
  3. Develop and beautify the.vnet based on weblog and Weblog
  4. Developing blog project based on ABP vNext and. Net core – data access and code first
  5. Development of blog project based on ABP vNext and. Net core
  6. Developing blog project based on ABP vNext and. Net core – unified specification API, packaging return model
  7. Developing blog project based on ABP vNext and. Net core
  8. Develop blog project based on ABP vNext and. Net core – access GitHub, protect your API with JWT
  9. Developing blog project based on ABP vNext and. Net core – exception handling and logging
  10. Developing blog project based on ABP vNext and. Net core – caching data with redis
  11. Developing blog project based on ABP vNext and. Net core integrating hangfire to realize timing task processing
  12. Developing blog project based on ABP vNext and. Net core
  13. Developing blog project based on ABP vNext and. Net core
  14. Developing blog project based on ABP vNext and. Net core
  15. Developing blog project based on ABP vNext and. Net core
  16. Developing blog project based on ABP vNext and. Net core
  17. Developing blog project based on ABP vNext and. Net core
  18. Blog project based on ABP vNext and. Net core
  19. Developing blog project based on ABP vNext and. Net core
  20. Developing blog project based on ABP vNext and. Net core
  21. Developing blog project based on ABP vNext and. Net core
  22. Developing blog project based on ABP vNext and. Net core
  23. Developing blog project based on ABP vNext and. Net core
  24. Developing blog project based on ABP vNext and. Net core
  25. Developing blog project based on ABP vNext and. Net core
  26. Developing blog project based on ABP vNext and. Net core
  27. Developing blog project based on ABP vNext and. Net core
  28. Developing blog project based on ABP vNext and. Net core
  29. Developing blog project based on ABP vNext and. Net core
  30. Developing blog project based on ABP vNext and. Net core

Finally, the API was developed, followed by the blazor version of the blog project to celebrate the end of this series of articles.

Now that the development is completed, it’s better to take it out for a stroll. This is the last article in this series. I’m going to deploy the API to Linux and deploy the blog developed by front-end blade to GitHub pages.

  • blog:https://blazor.meowv.com/
  • api:https://api2.meowv.com/

First put the address, experience it, and be patient. The first visit will download the resource file to the local browser, and the later visit will be quick.

It’s also the first time to use razor to develop a project. Anyway, this experimental blog with teaching and publicity purposes has been developed. If you use it yourself, you can do it. At the same time, you have gained a lot in the development process.

Publish API

To publish a self written backend API project, you must have your own server. Of course, if you just want to play with your own hands, there is no need. Because. Net core cross platform, we can choose at will. I will demonstrate how to publish the project to Linux.

Before that, you can take a look at my article last year. The personal blog developed based on. Net core was published to CentOS for a brief understanding.

My machine is a slag configuration server that used to roll wool a long time ago. It has 1G memory, 1 core CPU and 1 m bandwidth. However, for our small station, there is not much traffic, so it is still used.

First of all, you need to install the. Net core runtime environment. You can install the latest. Net core 3.1 directly. This step is based on the official documents of Microsoft, https://docs.microsoft.com/zh-cn/dotnet/core/install/linux 。

It can be used after installationdotnet --list-runtimesView the runtime.

1

Then you can install nginx, a high-performance web server, and use its reverse proxy function here. Of course, its function is much more than that. About the installation of nginx I do not say, if you do not understand, there are too many tutorials on the Internet.

It can be used after installationnginx -VCheck the installation version and other information.

2

At this step, we can deploy our API project and directly use visual studio to package and publish the project,appsettings.jsonFill in the configuration file information. I don’t need to say much about this step. I believe everyone will.

3

Use winscp tool to upload the published code to the server. I have created a new folder, Qix / api2, to facilitate my management. By the way, winscp is an open source graphical SFTP Client for SSH in Windows environment.

4

Now we can locate the API directory in the terminal,cd /qix/api2, and then execute the command to start the projectdotnet run Meowv.Blog.HttpApi.Hosting.dllAt this time, we will see the output information, and we can use the server IP + port to access the API.

If it’s just like this, it’s definitely not what I want. At this time, we introduce the daemons under Linux, which is similar to the services under windows. When we shut down, restart or other abnormal problems occur, we can automatically restart the application, that is, automatic executiondotnet run xxx.dllThis command.

As for the daemons, supervisor and PM2, the former is developed based on python, and the latter is developed based on nodejs.

We choose supervisor here. Of course, PM2 is also good and can be used.

Installing supervisor under CentOS is also very simple. Paste a few lines of code directly and execute it according to it.

yum install python-setuptools

easy_install supervisor

mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf

After the installation is successful, you need to take some time to configure it and find the file / etc / Supervisor/ supervisord.conf Remove the comment at the end of the file and change it to the following.

...
[include]
files = conf.d/*.ini

At this time, you can listen to the INI configuration file under the conf. D folder, create a new folder conf.d under / etc / Supervisor /, and create a new configuration file api2 under the conf.d folder_ meowv.conf The name of the document is as follows:

[ program:api2_ meowv] # api2_ Meowv program name
command=dotnet  Meowv.Blog.HttpApi . Hosting.dll  #Orders executed
Directory = / Qix / api2 ා the directory where the command is executed
environment=ASPNETCORE__ Environment = production ා environment variable
user=root
stopsignal=INT 
Autostart = true ා whether to self start
Autorestart = true ා whether to restart automatically
Startsecs = 3 ා auto restart interval (s)
stderr_ logfile=/var/log/api2. meowv.com.err . log # the error log file points to the directory
stdout_ logfile=/var/log/api2. meowv.com.out . log ා the output log file points to the directory

Each line is annotated, so you know exactly what it is used for. Here are some common commands:

supervisorctl start program_ Name ා start a process (program_ Name = configured process name)
supervisorctl stop program_ Name ා stop a process
Supervisorctl reload ා restarts all programs in the configuration
Supervisorctl stop all ා stops all processes
Supervisorctl update ා updates the new configuration to supervisor
supervisorctl restart program_ Name ා restart a process
Supervisorctl ා view the waiting process

5

Use the above command to start the project successfully. It must be unfriendly to use IP + port to access API. At this time, a domain name is needed. I will create a new secondary domain name api2 meowv.com Implement the newly developed API project.

About the domain name resolution what not to say, after configuring the domain name, I applied for an SSL certificate by the way, using the way of HTTPS access.

At this point, you can configure the nginx direction proxy. Go to the nginx installation directory. Here is / etc / nginx. Create a new folder SSL, put the SSL certificate applied in, and then create a new api2 under the conf.d folder_ meowv.conf File, write the following configuration information.

server {
        listen 443 ssl;
        server_name api2.meowv.com;
        ssl_certificate ssl/1_api2.meowv.com_bundle.crt; 
        ssl_certificate_key ssl/2_api2.meowv.com.key; 
        ssl_session_timeout 5m;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
	ssl_prefer_server_ciphers on;
        location / {
             if ($request_method = 'OPTIONS') {
		add_header Access-Control-Allow-Headers 'Authorization,Content-Type';
             	add_header Access-Control-Allow-Origin *;
             	add_header Access-Control-Allow-Credentials true; 
             	add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
             	return 204;
             }
             proxy_pass http://localhost:5009;
             proxy_set_header   X-Real-IP        $remote_addr;
             proxy_set_header   Host             $host;
             proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
	     client_max_body_size 20M;
        }
}

server {
	listen 80;
	server_name api2.meowv.com;
	rewrite ^(.*)$ https://api2.meowv.com;
}

6

You can learn about the configuration information by yourself. I also use it here. The port I listen to is 5009, which can be customized in the API project. I believe you all know. After the above operations are completed, execute them in the terminalnginx -s reloa, refresh the nginx configuration to make it work, and then it’s done.

About the database and redis cache in the project, you can install it yourself. The database can choose to use SQLite. The database has been switched by one key in the project. Installing redis is also very simple. I believe you can complete it by yourself. Redis can be used or not, and can be closed directly.

7

Now the API project has been successfully released. It is deployed under the Linux system, with the API running normally online. Next, I will also post the blog developed by the front-end blade.

Publish blog

In order to save server resources, there are so many things in it now. I am going to deploy blog on GitHub pages.

After being released with blade web assembly, it is a pure static file, so it can be placed anywhere. It has nothing to do with the environment, as long as you can open a web service.

Create a repository on GitHub to store our post release code. For information about creating a repository, see here, https://pages.github.com 。

Next, we will release the blade project. Before publishing, we will change the API address. Of course, this can also be made in the form of a configuration file.

7

8

Then clone the created repository and copy the blog static file into it. At this time, we can’t directly push it into the repository. In order to adapt to GitHub pages, we need to make some changes.

GitHub pages use Jekyll. Folders that start with special characters will not be mapped to the route. The static file we published just contains a_Folder at the beginning_frameworkIn order to solve this problem, a warehouse can be created below.nojekyllName the empty file.

According to the actual operation and trampling, if you publish, you will still report an error that cannot load resourcesThe resource has been blocked., and then found a solution in GitHub, as shown in: https://github.com/dotnet/aspnetcore/issues/19907#issuecomment -600054113 。

Create a new one.gitattributesFile, write content:* binaryNow push the file to the warehouse.

Then turn on the GitHub pages function option under the settings of the warehouse.

9

A custom domain name can also be added here for a custom domain nameCNAMEThe content in the file is your domain name. Here I am: blazor.meowv.com 。

10

Finally, configure the CNAME resolution of the domain name, wait for DNS to take effect, and then you can use the custom domain name to access.

Conclusion

This series of articles from scratch to build an API, using razor to develop a simple blog system, not a lot of functions. On the whole, I have stepped on the pit from scratch, and I have gained a lot.

Here, I want to thank those who have appreciated me again official account.

Maybe not a lot of things are involved in the whole. There is no breadth and depth. It’s just a very basic use. I have said before writing that these series are used to record their own coding process. Because the big guys are not willing to share, we can only do this level.

If it doesn’t help you, you should have seen it, smile or point a little fork in the upper right corner ❌❌ Because no matter what you do, there are always people who like to gossip~~

If there is some help for you, please promote it more. ✨✨✨

Finally, you can pay attention to my WeChat official account.A Xing plus』🤞🤞🤞

Because of the epidemic situation, the college entrance examination of this year was postponed to July. The annual college entrance examination is the peak business period of my company. I’m really busy and I don’t have time to write. I’m just ready to take a break for a while. I’ll bring you better articles later. I’ll see you in the next series.

This series of articles code open source address: https://github.com/meowv/blog

11