I recently bought the cheapest Tencent cloud server, which is mainly used to deploy my personal blog and learn some liunx knowledge, so as to fully understand and master web technology. It is strongly recommended that front-end personnel have their own server. Before writing this article, My cloud server has already installed Mysql, node, nginx, etc. Let's take the deployment of a node website as an example to explain several common scenarios Threads run persistently Generally speaking, we start a server through node index.js on the window cmd. As long as it is not closed, we can always access and call the interface. However, on Linux, if you do not operate for a long time or you want to perform other operations, your node service will be disconnected and users will not be able to access your website. what to do? We can install the forever module to solve this problem. npm install forever -g // Globally install the forever module Just change the original startup method node index.js to forever start index.js. Here are some common commands forever list // List all currently running services forever start -w index.js // Automatically restart on file change forever stopall // Stop all services forever stop app.js // Stop one of the node Apps forever stop [id] // forever list finds the corresponding id, then Of course there are many more commands, you can refer to the relevant modules. Generally speaking, the simplest way to use it is: forever start index.js In this way, even if we switch to other Linux paths or exit, the node service still exists, that is, others can still access your website. Configure nginx nginx is a reverse proxy server developed by Russians and is now used by many companies around the world. For the introduction and installation of nginx, you can read the information yourself or learn quickly from the novice tutorial. Here my Linux has already installed nginx. Next, I will use nginx to proxy http://localhost:8089 that was just started by forever start index.js, that is, to access the website http://localhost:8089 through my domain name. View the nginx configuration file path find / -name nginx.conf Switch to it and modify the configuration inside server { listen 80; # Just configure the listening port to 80 server_name hellocode.xyz; # Enter the domain name and it will jump to http://localhost:8089 include /etc/nginx/default.d/*.conf; location / { proxy_pass http://118.89.33.75:8089; # Your node website application} error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } Exit to check whether the configuration is correct nginx -t Reload nginx nginx -s reload Open the browser and enter the URL to access the website! You may encounter cross-domain problems during the access process, so you need to set up the node side to support cross-domain. For the express framework, customize a middleware in index.js var allowCors = function(req, res, next) { res.header('Access-Control-Allow-Origin', req.headers.origin); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); res.header('Access-Control-Allow-Headers', 'Content-Type'); res.header('Access-Control-Allow-Credentials','true'); next(); }; app.use(allowCors); //Use cross-domain middleware Regarding cross-domain issues, the following blog will explain in detail! The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of performance optimization ideas for React functional components
>>: Pitfalls encountered when installing the decompressed version of MySQL 5.7.20 (recommended)
I often see some circular wave graphics on mobile...
Table of contents 1. Write in front 2. Overlay to...
Table of contents 1. Brief Overview 2. JSON basic...
Mysql auto-increment primary key id does not incr...
Writing a Dockerfile Taking the directory automat...
This article shares the installation and configur...
01. Overview Absolute paths and relative paths ar...
Table of contents 1. Preparation 1. Prepare the e...
Recently, when I was writing a WeChat applet, the...
echarts component official website address: https...
The TextBox with the ReadOnly attribute will be di...
Classical color combinations convey power and auth...
The party that creates a new connection is equiva...
This article shares the specific code of jQuery t...
Table of contents Problem Description Historical ...