Detailed nginx log file transfer speed limit client to configure multiple virtual host server

Detailed log files nginx **

nginx log files into log_format and access_log two parts

Log_format definition record format, the syntax is

log_format style name style details

There is a default configuration file

log_format  main  'remote_addr - remote_user [time_local] "request" '
                  'status body_bytes_sent "$http_referer" '
                  '"http_user_agent" "http_x_forwarded_for"';

Here Insert Picture Description
Here Insert Picture Description
Use limit_rate limit the speed of data transfer client **

1, edit /etc/nginx/nginx.conf

location / {
            root   /var/www/nginx/;
            index  index.html index.htm;
            limit_rate  2k;  #对每个连接的限速为2k/s
}

1, edit /etc/nginx/nginx.conf

location / {
            root   /var/www/nginx/;
            index  index.html index.htm;
            limit_rate  2k;  #对每个连接的限速为2k/s
}

Finished modifying the configuration file, need to restart the service (reload service)

Points to note:

  • The profile of each statement should take; end
  • 7, nginx Virtual Host Configuration

What is Web Hosting?
Hosting is a special hardware and software technology, it can be every computer on the network into a plurality of virtual hosts, each virtual host can independently provide external www services, this can be achieved to provide a plurality of external host web service, are independent between each virtual host, independently of each other.
Here Insert Picture Description
nginx can achieve virtual host configuration, nginx supports three types of virtual host configuration.
1, based virtual hosting (server_name to distinguish between virtual hosts - Application: External website)
2, ip-based virtual host, and (a host bind multiple ip address)
3, based on the virtual host port (port to distinguish virtual host - application: the company's internal Web site, external website management background)
the primary configuration server module on it, you can put the main server configuration file comments, and then again in the new configuration under /etc/nginx/conf.d/ end with .conf file must be written on what content to
the main configuration file must include /etc/nginx/conf.d/*.conf (at http module below)
1, name-based virtual hosting

1, configured through domain name to distinguish the virtual machine

 server {
        listen       80;
        server_name  web.testpm.com;
        location / {
            root   /var/www/nginx/;
            index  index.html index.htm;
            limit_rate	2k;
        	}
        }
    
    server {
        listen       80;
        server_name  web.1000phone.com;
        location / {
            root   /1000phone/html;
            index  index.html index.htm;
        	}
        }
[root@localhost nginx]# vim /var/www/nginx/index.html 
hello tianyun

2, for the domain name web.1000phone.com virtual machine, create index file

[root@localhost ~]# mkdir -p /1000phone/html
[root@localhost ~]# vim /1000phone/html/index.html
this is my 1000phone

3, reload the configuration file

# 如果编译安装的执行
[root@nginx]# /usr/local/nginx/sbin/nginx -s reload
# 如果 yum 安装的执行
[root@nginx]# nginx -s reload

4, the client configuration parsing
in C: \ Windows \ System32 \ drivers \ etc \ hosts file to add two lines (linux: / etc / hosts)

10.0.105.199 web.testpm.com
10.0.105.199 web.1000phone.com

5, test access

Enter the browser: http: //web.testpm.com/

Enter the browser: HTTP: //web.1000phone.com/
2, ip-based virtual hosts

[root@localhost ~]# ip a 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:17:f1:af brd ff:ff:ff:ff:ff:ff
    inet 10.0.105.199/24 brd 10.0.105.255 scope global dynamic ens33
       valid_lft 81438sec preferred_lft 81438sec
    inet6 fe80::9d26:f3f0:db9c:c9be/64 scope link 
       valid_lft forever preferred_lft forever
       
[root@localhost ~]# ifconfig ens33:1 10.0.105.201/24  #增加虚拟ip
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.105.199  netmask 255.255.255.0  broadcast 10.0.105.255
        inet6 fe80::9d26:f3f0:db9c:c9be  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:17:f1:af  txqueuelen 1000  (Ethernet)
        RX packets 9844  bytes 1052722 (1.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5567  bytes 886269 (865.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.105.201  netmask 255.255.255.0  broadcast 10.0.105.255
        ether 00:0c:29:17:f1:af  txqueuelen 1000  (Ethernet)

2, the configuration of the virtual machine by distinguishing ip

server {
        listen       80;
        server_name  10.0.105.199;
        location / {
            root   /var/www/nginx/;
            index  index.html index.htm;
            limit_rate	2k;
        }
        
     server {
        listen       80;
        server_name  10.0.105.201;
        location / {
            root   /1000phone/html/;
            index  index.html index.htm;
        	}
        }

3, reload the configuration file

[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

4, test access
browser enter: http: //10.0.105.199
browser enter: HTTP: //10.0.105.201
5, supplement
- remove the binding of temporary ip

[root@localhost ~]# ifconfig ens33:1 10.0.105.201/24 down

Restart the nginx

[root@localhost ~]# systemctl restart nginx

3, Port-based virtual hosts

 server {
        listen       80;
        server_name  web.testpm.com;
        location / {
            root   /var/www/nginx/;
            index  index.html index.htm;
            limit_rate	2k;
        }
        
    
     server {
        listen       8080;
        server_name  web.testpm.com;
        location / {
            root   /1000phone/html/;
            index  index.html index.htm;
        	}
        }

Reload the configuration file:

[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

Test Access:
browser, enter: http: //web.testpm.com/
browser and enter: http: //web.1000phone.com: 8080

Published 48 original articles · won praise 18 · views 3656

Guess you like

Origin blog.csdn.net/wx912820/article/details/104823823