binq2000 2024-07-26 00:44 采纳率: 16.7%
浏览 11

nginx配置奇怪的问题

nginx 1.25.1仅配置了内网IP192.168.1.103的访问,但是输入公网IP也能访问到系统页面,具体配置如下:


#user  nobody;
worker_processes  1;

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

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  10.43.112.200;
        root /home/www;
        charset utf-8;
        #access_log  /var/log/nginx/log/host.access.log  main;

        location / {
            index  index.php index.html index.htm;
            proxy_connect_timeout 300s;
            proxy_send_timeout 300s;
            proxy_read_timeout 300s;
            client_max_body_size  50m;
            client_body_buffer_size 5m;
        }

        error_page  404              /error-404.html;
        error_page  403              /error-403.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;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
        #    root           html;
            client_body_temp_path /tmp;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_read_timeout 300;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
             expires off;
        }
        add_header X-Content-Type-Options nosniff;
        add_header 'Referrer-Policy' 'origin';
        add_header X-Download-Options "noopen" always;
        add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
        add_header X-Permitted-Cross-Domain-Policies  "master-only";
        add_header X-Frame-Options SAMEORIGIN;
        add_header Content-Security-Policy "default-src 'self' data: *.xxx.com  'unsafe-inline' 'unsafe-eval' mediastream: ";
        add_header X-Content-Type-Options: nosniff;
        add_header X-XSS-Protection "1; mode=block";
        location ~ ^/log {
            deny all;
        }
    }

}


  • 写回答

2条回答 默认 最新

  • 专家-赤兔[在线] 全栈领域优质创作者 2024-07-26 00:44
    关注

    引自免费微信小程序:皆我百晓生

    从你提供的配置来看,你的Nginx确实配置了只监听内网IP地址(192.168.1.103)。然而,你提到输入公网IP也能访问到系统页面,这可能涉及到一些其他配置或者网络设置。这个问题可能有以下几个原因:

    1. DNS配置问题:如果DNS解析中同时配置了公网IP和内网IP指向同一主机,那么通过公网IP也能访问到服务器。你需要检查DNS配置是否正确。
    2. 路由器配置问题:如果你的路由器配置了对公网IP的转发,那么即使Nginx配置只监听内网IP,也能通过公网IP访问。检查你的路由器设置是否有端口转发或其他相关设置。
    3. 防火墙配置问题:某些防火墙可能允许来自公网的请求直接穿透到内网服务器。确认你的防火墙设置是否正确。

    针对这些可能的问题,你可以采取以下措施进行排查和解决:

    1. 检查DNS配置:确认DNS解析是否同时配置了公网IP和内网IP指向同一主机。如果是这样,你可能需要修改DNS配置,只使用内网IP进行解析。
    2. 检查路由器设置:确认路由器是否对公网IP进行了端口转发或其他相关设置。如果是的话,你可能需要修改路由器设置,停止对公网IP的转发。
    3. 检查防火墙设置:确认防火墙是否允许来自公网的请求直接穿透到内网服务器。如果是的话,你可能需要修改防火墙规则,阻止来自公网的未经授权的访问。

    在检查以上配置的同时,也请确保Nginx的配置文件没有其他地方存在可能导致公网访问的配置错误。如果有必要,可以尝试重启Nginx服务以查看是否解决了问题。如果问题仍然存在,你可能需要进一步深入调查网络环境和服务器配置。

    评论 编辑记录

报告相同问题?

问题事件

  • 修改了问题 7月26日
  • 创建了问题 7月26日

悬赏问题

  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见
  • ¥15 一共有五道问题关于整数幂的运算还有房间号码 还有网络密码的解答?(语言-python)
  • ¥20 sentry如何捕获上传Android ndk 崩溃
  • ¥15 在做logistic回归模型限制性立方条图时候,不能出完整图的困难
  • ¥15 G0系列单片机HAL库中景园gc9307液晶驱动芯片无法使用硬件SPI+DMA驱动,如何解决?