This article describes how to use Nginx to build multiple websites on the ECS instance of the server system.
1. First, you need an ECS instance, as shown in the figure below (note that the operating system is CentOS 7.4)
2. Remotely connect to our server through Workbench to enter the operating system
Then log in
and then log in to the instance, the account password is set by yourself
3. First install the following three software Nginx, MySQL, PHP
The version should not be too old
Nginx version: Nginx 1.16.1
MySQL version: MySQL 5.7.28
PHP version: PHP 7.0.33
You can use the command to check whether your system has corresponding software. If there is a corresponding version number, it means that it is
installed or not , or you can create a mirror (I use wordpress blog system) and go to the mirror market to build one.
Either install and configure it yourself, here is the official link of Alibaba Cloud
https://help.aliyun.com/document_detail/97251.htm?spm=a2c4g.11186623.2.9.179b6c7bKO2mQR#concept-fnh-v3x-5fb
4. Start creating a test site
1. Run the following command to enter the root directory of the configured website
cd /usr/share/nginx/html
2. Run the following command to create two test folders.
The folder is used to store the test website information, that is, store the project code.
mkdir Testpage-1
mkdir Testpage-2
3. Configure the information of the test site Testpage-1.
Run the following command to enter Testpage-1
cd /usr/share/nginx/html/Testpage-1/
Run the following commands to create and edit the index.html file.
vim index.html
Press i to enter edit mode and enter the following test content.
Test page 1
4. Then Testpage-2 is the same
cd /usr/share/nginx/html/Testpage-2/
vim index.html
Test page 2
5. Configure Nginx
Run the following command to enter the /etc/nginx/conf.d path.
cd /etc/nginx/conf.d
Create and configure Nginx configuration file for test site Testpage-1
vim Testpage1.conf
Enter the following content.
The place with # can be changed.
If there is a domain name, you can write your own domain name for the test domain name. If not, fill in localhost , which is your own IP
listening port, which is listen. Fill in the security group you set up yourself (mine It is 5000) There are methods below
server {
listen 5000; #改成自己设置的安全组端口 我的是5000
server_name localhost; #可以使用自己的域名。实际配置中使用您的服务器域名 没有则用localhost
#charset koi8-r;
access_log /var/log/nginx/b.access.log main;
location / {
root /usr/share/nginx/html/Testpage-1; #测试站点路径。即您的项目代码路径。
index index.html index.htm;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
How to set the security group port?
I set a 5000, then fill in 5000 in the listen field,
manually add and fill in the port number 5000, and create Testpage2.conf according to the figure below
is the same method
vim Testpage2.conf
server {
listen 5001; #自己设置多少就是多少
server_name localhost; #此处使用测试域名。实际配置中使用您的服务器域名。
#charset koi8-r;
access_log /var/log/nginx/b.access.log main;
location / {
root /usr/share/nginx/html/Testpage-2; #测试站点路径。即您的项目代码路径。
index index.html index.htm;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
6. Finally, run the following command to restart the Nginx service
systemctl restart nginx
Enter your own IP on the webpage: 5000, and you can see the index and html
phenomenon you just set: