nginx - 带和不带通配符的 nginx 域
问题描述
我有 nginx 配置文件,它必须服务器 example.com 和 www.example.com。
server {
listen 80;
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
listen 80;
server_name www.example.com;
auth_basic "example Login";
auth_basic_user_file /etc/nginx/.htpasswd;
root /projects/www/example;
index index.html;
location ~* \.(html|js|jpg|png|gif|css|perfumes|imgs|map|fonts|otf)$ {
index index.do index.html index.htm;
access_log off;
}
location /.protected {
access_log off;
auth_basic off;
}
location /health {
access_log off;
auth_basic off;
}
location / {
try_files $uri $uri/index.html;
}
location /hello {
proxy_pass http://localhost:8282;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
我现在正在尝试保护这个域,因为我们正在准备发布。但是,如果链接中包含“.protected”,则只有一个链接可以让请求在没有密码的情况下通过。
例如,
应该允许 www.example.com/.protected/file1.txt 不输入密码。
它工作正常,但问题是 example.com/.protected/file1.txt(没有“www”)。
如果我只输入域名“example.com”(没有“www”),它会按照配置自动重定向到 www.example.com,但“example.com/.protected/file1.txt”不会重定向到“www” .example.com/.protected/file1.txt'。似乎如果域名有一些路径,域名(没有“www”)不会重定向到“www.example.com”
我得到'卷曲:(6)无法解析主机:'
我的配置文件有什么问题吗?
解决方案
推荐阅读
- python - 感染效率 - Pygame
- android - 在扩展函数(kotlin)中传递带参数的函数
- flutter - Flutter 构建面向开发和产品风格的 AAR(构建变体)
- javascript - 在我的反应应用程序上使用 map() 方法时遇到一些问题
- jmeter - Jmeter chrome webdriver - 将pageloadstrategy设置为none
- android - 为什么来自我的 Android WebView 应用程序的流量显示为“直接”?
- c# - ILogger 调试消息未显示在 NLog 目标中
- amazon-web-services - Firehose 数据转换 lambda - 从单个运动记录生成多个记录
- javascript - 当我拖动范围滑块时,什么 DOM 事件允许持续触发?
- three.js - 仅在 Hover three.js 上更改颜色