zoukankan      html  css  js  c++  java
  • nginx配置其他的服务和ip禁止访问

    被别人的域名指定向自己的ip如何配置

    http {
        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  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        include /etc/nginx/conf.d/*.conf;
    
        server {
            listen       7070;
            server_name  www.syscal.xyz;#指定的域名
            root         /usr/share/nginx/html;
            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;
    
            location / {
            }
    
            error_page 404 /404.html;
                location = /40x.html {
            }
    
            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
        }
      # 禁止其他域名和ip访问
        # 这个default_server 得放在这里,如果放在上面的情况 就会报错了
        #return 500 就是返回了500报错信息,也可以变成403
       server {
            listen 7070 default_server;
            server_name _;
            return 500;
        }
    
    }

    或者另外的方式:

    server {
            listen       80;
            server_name  www.test.com;
    
        if ($host != 'www.test.com'){
           return 403;
        }
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            #location / {
            #    root   html;
            #    index  index.html index.htm;
            #}
            location / {
            #root   /usr/share/nginx/html;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_ignore_client_abort on;
            proxy_send_timeout  600s;
            proxy_read_timeout  600s;
            #禁用缓存
            proxy_buffering off;
            #index  index.html index.htm;
            proxy_pass   http://dxb_new;
            }
    
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }

    配置禁止其他ip访问在nginx解析中增加如下配置即可:

    server
    {
    listen 80 default;
    server_name _;
    return 500;
    }

  • 相关阅读:
    iOS 苹果开发证书失效的解决方案(Failed to locate or generate matching signing assets)
    iOS NSArray数组过滤
    App Store2016年最新审核规则
    iOS 根据字符串数目,自定义Label等控件的高度
    iOS 证书Bug The identity used to sign the executable is no longer valid 解决方案
    Entity FrameWork 增删查改的本质
    EF容器---代理类对象
    Entity FrameWork 延迟加载本质(二)
    Entity FrameWork 延迟加载的本质(一)
    Entity FrameWork 增删查改
  • 原文地址:https://www.cnblogs.com/zhangshiwen/p/12218035.html
Copyright © 2011-2022 走看看