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)
Find the problem When retrieving the top SQL stat...
1. Apache server installation and configuration y...
Table of contents Introduction to stored procedur...
Give time time and let the past go. In the previo...
1. Download the ubuntu16.04 image and the corresp...
Preface The <router-link> tag is a great to...
Preface This article uses pdo's preprocessing...
1. Create the /usr/local/services/zookeeper folde...
GitHub address, you can star it if you like it Pl...
The elements in an HTML document are arranged one...
This article shares a simple HTML shopping quanti...
1. Introduction to LVM When we manage Linux disks...
1. CSS Miscellaneous Icons There are three ways t...
How to change the MySQL database directory locati...
This article uses examples to illustrate the usag...