Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of creating multiple websites on one server

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "the method of creating multiple websites on one server". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. let's study and learn "how to create multiple websites on one server".

Principle analysis

The essence is that Nginx listens on port 80 of a server, using different domain names to map to different Linux file directories (directories published by the site)

The first is that multiple domain names can be resolved to the same ip address. Our virtual hosting technology is realized by using this point. In general, we identify a website by its ip and port as well as the site project name. In the test environment, you can deploy multiple sites under the same host by changing to different ports or by changing the project name of the site. But in the real production environment, our websites tend to use port 80, and there is no site directory path. At this time, websites can be distinguished by different domain names. The specific implementation process is as follows: first, multiple domain names are resolved to the same host ip by configuring domain name resolution, and then we configure the host to forward requests from different domain names to different website programs for processing. The host intercepts the request header information of the request, and then obtains the value of the request header host, which is the source domain name of the request. According to the corresponding relationship between the configured domain name and the website program, the host forwards the requests from different domain names to different programs for processing.

With this mapping relationship, when the host receives a request, it will first get the domain name in which the request is located, and then according to the corresponding relationship between the configured domain name and the website root directory, forward the request to the corresponding website root directory for processing.

This achieves the effect of deploying an infinite number of websites on one ip port 80.

Concrete scheme realization

In fact, it is very simple. Let's take the Ali Cloud server (here is the latest discount activity of Aliyun, remember to get the coupon and then buy it, save a little bit) as an example. Teach you to use the pagoda panel to deploy with one click and easily add multiple sites. (at step 12)

What is pagoda panel: pagoda Linux panel is a server management software to improve the efficiency of operation and maintenance. It supports more than 100 server management functions such as one-click LAMP/LNMP/ cluster / monitoring / website / FTP/ database / JAVA.

Use agent forwarding software. Such as Nginx reverse proxy. When I didn't know anything about Nginx in the past, I was worried about this problem for a long time. Later, with the learning of knowledge, the problem is found to be very simple, and the solution is also simple, which can solve your problem through Nginx reverse proxy.

Use Nginx to listen on the same port (port 80) of the same CVM, and then forward it on behalf of different domain names. Under the CVM, you can specify each domain name to access a specific Linux file directory, and each file directory publishes your site. In this way, one server can publish multiple sites.

Server {listen 80 default_server; server_name www.yundashi168.com; # Domain name 1 index index.php index.html index.htm default.php default.htm default.html; root/www / wwwroot/www.yundashi168.com/site1 # site 1 / / the following code is omitted} server {listen 80 default_server; server_name tencent.yundashi168.com # Domain name 2, and so on, you can build countless sites index index.php index.html index.htm default.php default.htm default.html Root/ www/wwwroot/tencent.yundashi168.com/site2 # site 2 / / the following code omits} multiple nginx configuration files can split # REWRITE-START URL rewriting rule references. Modification will invalidate the pseudo-static rules set on the panel include / www/server/panel/vhost/rewrite/www.yundashi168.com.conf; # refer to site 1 configuration files in the overall configuration file

If you are a pure rookie, do not know much about technology, it is recommended to use pagoda panel, pagoda panel one-click installation and deployment of Nginx software environment, do not need you to build by hand, and in use, do not need to write any commands. As long as you can use the pagoda panel.

In the past, I used to build the running environment such as nginx+mysql+php by hand, and the pagoda panel was used directly in the background in order to save time and energy. Then the pagoda panel can help me build multiple websites on one server.

As for how many websites can be built? It all depends on how many website visits and resource consumption your server can hold. If your CVM is highly configured, such as a 4-core 16G configuration, you can build dozens of small websites without problems. Of course, the bandwidth has to be taken into account.

Pagoda panel to build multiple websites

If you want to refer to the relevant tutorials, it just so happens that I have summed up the classic tutorials written by my previous site. Teaches you how to install multiple sites on one server. The essence is to install LNMP (Linux+Nginx+Mysql+PHP) environment on the pagoda panel, using nginx to achieve.

Specific tutorial: pagoda panel to add WordPress site detailed graphics and text tutorials (of course, you do not have to build WordPress programs, but also any other programs and website systems)

If you know the technology, then as long as you know Nginx, implement your own Nginx proxy to deploy multiple websites on the server, then there is no problem at all.

Nginx deploys multiple projects

The overall process follows a set of core concepts

Requirements: deploy multiple WEB projects on a single server. And each project has its own domain name that can be accessed.

Solution:

Purchase a CVM and get the IP address

Purchase a domain name and resolve multiple second-level domain names to the IP address; (www.xxx.com- > 192.168.0.1 × cms.xxx.com-> 192.168.0.1 * abc.xxx.com-> 192.168.0.1)

Install nginx using Docker, which runs on a port on the server (we specify it ourselves)

Using SSH software such as xshell or finalshell, transfer our project to the static resource folder of the nginx installed in the previous step, so that we can access our "one WEB project" in the form of "ip address: Port number" such as 192.168.0.1 ip 90.

When we access an address such as 192.168.0.1, we access port 80 by default

So we can use docker to deploy multiple nginx on non-80 ports of the same server, all of which deploy different WEB projects, such as "official website" in 192.168.0.1 WEB 90 and "web games" in 192.168.0.1 WEB 100.

Finally, we deploy a nginx as a "reverse proxy server" on port 80 of the server, and configure the correspondence between "domain name" and "ip: Port number" in this reverse proxy server. (as shown below)

So we can access different projects deployed on the same server through different domain names! okay!

Thank you for your reading. the above is the content of "the method of creating multiple websites on one server". After the study of this article, I believe you have a deeper understanding of the method of creating multiple websites on one server. the specific use also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report