Nginx-HTTP server
Presentation environment:
System version : CentOS Linux Release 7.7.1908 (Core)
nginx version : nginx / 1.16.1
Of course, the official explanation is the best : English and Russian chiefs venue's official website please click here
A, HTTP server
1 Introduction
The HTTP : one is to pass data (HTML files, image files, etc.) working in the HTTP application layer protocol based on a TCP / IP communication protocol.
Hosting of: a physical server into several virtual servers, different virtual machines to access through the port, called a virtual host.
Each virtual host corresponds to a web site is to build multiple sites on a single server.
Second, the virtual host configuration
1. Prepare
- I record the domain name: tianyao.site (not does not matter, we can set the local hosts file to test use)
- Create a web directory, file upload page
- These are the premise we installed Nginx, not installed can refer to the first article
mkdir /www
cd /www
mkdir tianyao //我这里的目录就以域名命名
echo 2020年4月4日 向英雄致敬,向逝者致哀。> tianyao/index.html
2. Configure virtual hosts
Virtual host in three ways
- Port-based (based on commonly used ports)
- Based on different IP addresses (I now use Ali cloud server, there is only one public address, temporarily unable to demonstrate)
- Based on a different domain name
- This /etc/nginx/conf.d/ heads are empty when there is no virtual host, you can create your configuration, but at the end .conf.
vim /etc/nginx/conf.d/tianyao.conf
# 基于域名的配置
server {
listen 80;
# server_name www.tianyao.site;
location / {
root /www/tianyao/;
index index.html index.htm;
}
}
#基于端口的网页
server {
listen 8080;
location / {
root /www/tianyao/;
index index.html index.htm;
}
}
3. DNS settings
- For the record domain name, add an A record to point to your host. Different analytical methods are not the same provider, demonstrated here to configure Western Digital.
- If you do not record the domain name, you can learn to use to configure DNS on the client host:
Windows 10: C: \ Windows \ System32 \ driversletclhosts
Linux / Mac: / etc / hosts - Cloud server (home server), websites need to be able to add the record to resolve, but the filing period is longer, the record can not use free URL forwarding, but the domain name must be the real name for the record.
4. Test
After setting we can enter the domain name in the browser:
Page prompts insecurity we are here to resolve using https
Three, Nginx related notice
(. 1) the Nginx environmental structures
(2) HTTP server (current)
(. 3) Detailed the HTTPS service
(4) reverse proxy
(5) the load balancer
(6) separating movement