VPS侦探论坛

 找回密码
 注册
查看: 3349|回复: 4

请教怎样禁止访问域名根目录,其他非根目录正常访问

[复制链接]
发表于 2019-3-30 11:00:55 | 显示全部楼层 |阅读模式

请教怎样禁止访问域名根目录,其他子目录正常访问
例如:www.abc.com打开返回403
www.abc.com/aa/1.html等这些都能正常访问
http配置的时候
我在nginx的server最后增加下面的
location = / {return 403;}
这样就能实现  根目录打不开,非根目录正常打开

但是我换成https
这样配置就全部都不能访问,请教军哥大神是怎么回事?

美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2019-3-30 11:19:47 | 显示全部楼层


http其他作用的话,https是一样的,只不过https多个ssl证书的设置

要不你贴一下配置文件看看
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2019-4-1 15:59:22 | 显示全部楼层

licess 发表于 2019-3-30 11:19
http其他作用的话,https是一样的,只不过https多个ssl证书的设置

要不你贴一下配置文件看看 ...
  1. server
  2.     {
  3.         listen 80;
  4.         #listen [::]:80;
  5.         server_name www.aaa.com ;
  6.         index index.html index.htm index.php default.html default.htm default.php;
  7.         root  /home/wwwroot/aaa;
  8.         return 301 https://www.aaa.com$request_uri;

  9.         include rewrite/none.conf;
  10.         #error_page   404   /404.html;

  11.         # Deny access to PHP files in specific directory
  12.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

  13.         include enable-php.conf;

  14.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  15.         {
  16.             expires      30d;
  17.         }

  18.         location ~ .*\.(js|css)?$
  19.         {
  20.             expires      12h;
  21.         }

  22.         location ~ /.well-known {
  23.             allow all;
  24.         }

  25.         location ~ /\.
  26.         {
  27.             deny all;
  28.         }

  29.         access_log off;
  30.     }

  31. server
  32.     {
  33.         listen 443 ssl http2;
  34.         #listen [::]:443 ssl http2;
  35.         server_name www.aaa.com ;
  36.         index index.html index.htm index.php default.html default.htm default.php;
  37.         root  /home/wwwroot/aaa;
  38.         ssl on;
  39.         ssl_certificate /usr/local/nginx/conf/ssl/www.aaa.com/fullchain.cer;
  40.         ssl_certificate_key /usr/local/nginx/conf/ssl/www.aaa.com/www.aaa.com.key;
  41.         ssl_session_timeout 5m;
  42.         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  43.         ssl_prefer_server_ciphers on;
  44.         ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
  45.         ssl_session_cache builtin:1000 shared:SSL:10m;
  46.         # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048
  47.         ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;

  48.         include rewrite/none.conf;
  49.         #error_page   404   /404.html;

  50.         # Deny access to PHP files in specific directory
  51.         #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

  52.         include enable-php.conf;

  53.         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  54.         {
  55.             expires      30d;
  56.         }

  57.         location ~ .*\.(js|css)?$
  58.         {
  59.             expires      12h;
  60.         }

  61.         location ~ /.well-known {
  62.             allow all;
  63.         }

  64.         location ~ /\.
  65.         {
  66.             deny all;
  67.         }

  68.         access_log off;
  69.         
  70.         location = / {
  71.                 return 403;
  72.         }
  73.     }
复制代码
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2019-4-1 16:00:47 | 显示全部楼层



licess 发表于 2019-3-30 11:19
http其他作用的话,https是一样的,只不过https多个ssl证书的设置

要不你贴一下配置文件看看 ...

没什么特别的配置,就加了
  1. location = / {
  2.                 return 403;
  3.         }
复制代码


这样就全部页面都是403
其他的基本都是lnmp自动生成的
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2019-4-1 17:07:00 | 显示全部楼层

蓝色枫 发表于 2019-4-1 16:00
没什么特别的配置,就加了

配置上没问题,这段代码也只匹配到 / 匹配不到其他页面不会导致其他页面403

军哥运维代购:http://shop63846532.taobao.com/

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-22 23:39 , Processed in 0.025628 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表