[英]Nginx subdomain only accessable locally
我正在尝试在我的 nginx 配置上设置一个 nginx 子域。 但我无法远程访问/浏览我的新子域。 尝试远程访问此子域时,不会记录任何错误/访问日志。 服务器托管在 Linode 上。
当前设置:默认 nginx 配置 -> 未编辑
主站点配置:
server {
listen 443 ssl;
server_name example.be www.example.be;
root /var/www/example;
index index.html
gzip off;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
ssl_certificate /etc/letsencrypt/live/example.be/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.be/privkey.pem; # managed by Certbot
}
server {
if ($host = www.example.be) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.be) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name www.example.be;
return 404; # managed by Certbot
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
子域配置:
server {
listen 80;
listen [::]:80;
root /var/www/sub.example.be;
index index.html index.htm index.nginx-debian.html index.php;
server_name sub.example.be;
location / {
try_files $uri $uri/ =404;
auth_basic "Restricted Area";
auth_basic_user_file /var/www/sub.example.be/.htpasswd;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
auth_basic "Restricted Area";
auth_basic_user_file /var/www/sub.example.be/.htpasswd;
}
location ~ /\.ht {
deny all;
}
}
我目前正在将 cloudflare 用于主站点 DNS 等。这是几个月前设置的,并且运行良好。
我只是在服务器(用于本地测试)和我的家用电脑(用于远程测试)上更改我的主机文件。
但是,我的 curl 命令无法正常工作:
服务器:curl sub.example.be/index.html
<html>
<head><title>401 Authorization Required</title></head>
<body bgcolor="white">
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.14.2</center>
</body>
</html>
我猜这是正确的行为。
但是当我从家里的电脑上这样做时: curl -v sub.example.be/index.html
* Trying [IP]...
* TCP_NODELAY set
* connect to [IP] port 80 failed: Timed out
* Failed to connect to sub.example.be port 80: Timed out
* Closing connection 0
curl: (7) Failed to connect to sub.example.be port 80: Timed out
哦,是的,我可以远程访问我的主域。
我的主网站显然将所有流量重定向到 HTTPS。
为我修复的是使用 certbot 上的 DNS 验证将 SSL 添加到我的子域。 复制主要的 nginx 配置并为我的子域更改它。
现在我可以通过 HTTPS 成功访问主域和子域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.