带和不带通配符的nginx域
我有一个nginx配置文件,它必须连接到example.com和www.example.com服务器带和不带通配符的nginx域,nginx,nginx-config,Nginx,Nginx Config,我有一个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 "exa
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”
我得到“curl:(6)无法解析主机:”
我的配置文件有什么问题吗?哪台主机不是由curl解析的,请您将curl详细记录在日志中。在我看来,您的nginx配置还可以,可能是您没有运行curl命令的www.example.com的主机条目。这就是我所得到的。*无法解析主机:example.com*正在关闭连接0:(6)无法解析主机:example.com。我在DNS记录类型“A”上添加了“www.example.com”。你能ping example.com和www.example.com吗?我能ping www.example.com,但我不能ping example.com。我有两个Web服务器和一个负载平衡器。负载平衡器向这两个web服务器发送请求。web服务器已启动并正在运行。因此,您无法访问example.com。这是实际问题,我认为您在DNS条目方面存在问题。只需将hosts条目放入example.com并查看即可。我想事情会很有魅力的!