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;
    }

  • 相关阅读:
    Python教程:从零到大师
    Hive 安装 & Mysql 安装
    Hive基本原理及配置Mysql作为Hive的默认数据库
    分布式存储系统-HDFS
    centos 6.4-linux环境配置,安装hadoop-1.1.2(hadoop伪分布环境配置)
    VirtualBox安装Centos出现E_FAIL (0x80004005)的解决方法
    Hadoop 中HDFS、MapReduce体系结构
    探索性测试及基本用例
    软件测试相关术语(测试策略 && 测试方案 ....)
    高效学习的疑问与思路[软技能]
  • 原文地址:https://www.cnblogs.com/zhangshiwen/p/12218035.html
Copyright © 2011-2022 走看看