Nginx configuration to achieve security chain function

Prepare two Linux, with a second linux host to take a picture by picture link to show the first host;

Because the host 2 via the host to take the picture link 1 so when others are accessible via a link pictures, is occupied by a host memory space, rather than the host memory space occupied 2

A) set to host a server-based company, once the non-company personnel to access the images via the link, will cause the server memory pressure. Therefore, to set up a non-company personnel can not access the link

Solution, do host a security chain function can effectively prevent non-company personnel to access pictures. To cause memory pressure ------- "This host 2 will even have access to see the picture image link

The first Ip address: 192.168.200.115

 

A second address value ip: 192.168.200.105

Not only add letters ago Pictures:

Changes index.html Add a picture:

[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# ls
50x.html    index.html
[root@localhost html]# vim index.html

Add image link under paragraph p 
<img src = "http://192.168.200.115/linux.jpg" / >

After adding pictures



Add the following in order of 1 server host

[root@localhost ~]# vim /usr/local/nginx/html/error.txt

<H1> Daolian shame </ h1>

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

Copy the code


user nginx nginx;
worker_processes 2;

#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;

pid logs/nginx.pid;


events {
     use epoll;
     worker_connections 10240;
}


http {
     include mime.types;
     default_type application/octet-stream;

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

    access_log logs/access.log main;

    sendfile on;

server_tokens off;
keepalive_timeout 65;

// NginX connection timeout codes
client_header_timeout 60;
client_body_timeout 60;

// Nginx web page compression turned Codes

gzip on;
#gzip _min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain text/javascript application/x-javascrip t text/css text/xml
application/xml application/xml+rss;


server {
listen 80;
server_name www.source.com;

charset utf-8;

access_log logs/crushlinux.com.access.log main;

location / {

   root html;
index index.html index.htm;
}

location ~* \.(js|css)$ {
     expires 1h;
}

location ~* \.(jpg|gif|png|swf)$ {
      #*.amber.com amber.com相当于公司域名
      expires 1d;
      root html;
      valid_referers none blocked *.source.com source.com;
      if ($invalid_referer) {
      rewrite ^/ http://www.source.com/error.txt;
   }
}

error_page 500 502 503 504 /50x.html;
     location = /50x.html {
     root html;
    }

   }
}

Copy the code

[root @ localhost ~] # killall -9 nginx // kill nginx process
[root @ localhost ~] # nginx // nginx open process
[root @ localhost ~] # killall -HUP nginx // reload

================================================================================

Real machine changes to the hosts file: hosts file is located (C disk windows, system32, drivers, etc in)

File content changes are as follows:

192.168.200.115 www.source.com
192.168.200.105 www.steal.com

=================================================================================

A host, the host browser to access the two comparison

www.source.com need to force a refresh the page press (shift + fn + f5)

 

www.sttal.com need to force a refresh the page press (shift + fn + f5)

Guess you like

Origin www.cnblogs.com/L1-5551/p/11518580.html