【发布时间】:2021-12-23 23:45:29
【问题描述】:
我正在尝试在我的 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
哦,是的,我可以远程访问我的主域。
【问题讨论】:
标签: wordpress nginx cloudflare linode