V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Cyshall
V2EX  ›  Kubernetes

ingress-nginx 使用 IP 访问 404,域名访问正常

  •  
  •   Cyshall · 2020-10-05 00:44:05 +08:00 · 3609 次点击
    这是一个创建于 1517 天前的主题,其中的信息可能已经有所发展或是发生改变。

    RT,是 ingress-nginx 本身就是这样,还是说有相关配置可以更改。

    以下是 nginx 相关配置:

    nginx.conf

    user  nginx;
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       /etc/nginx/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  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
    
        include /etc/nginx/conf.d/*.conf;
    }
    

    /etc/nginx/conf.d/default.conf

    server {
        listen       80;
        server_name  localhost;
    
        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    
        #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   /usr/share/nginx/html;
        }
    
        location = /hostname.html {
            alias /etc/hostname;
        }
    
        # 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;
        #}
    }
    
    4 条回复    2020-10-05 09:57:27 +08:00
    halfcrazy
        1
    halfcrazy  
       2020-10-05 01:45:00 +08:00   ❤️ 1
    取决你的 ingress 的配置。ingress 里配了 host,那么访问必须带 houst 。没配 host 的话,域名 ip 都可以
    oneoyn
        2
    oneoyn  
       2020-10-05 08:51:00 +08:00 via Android
    sendfile on;
    Cyshall
        3
    Cyshall  
    OP
       2020-10-05 09:20:36 +08:00 via Android
    @halfcrazy 感谢,但是我很奇怪阿,域名访问的第一步不就是查询域名对应的 IP 然后使用 IP 访问吗?这边 ingress 是咋做到这个限制的阿。
    bowser1701
        4
    bowser1701  
       2020-10-05 09:57:27 +08:00 via iPhone   ❤️ 1
    @Cyshall 根据 header 里面的 host 转发。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2901 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 02:40 · PVG 10:40 · LAX 18:40 · JFK 21:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.