【发布时间】:2021-02-08 01:07:01
【问题描述】:
我有一个由 Cloudflare 的免费工具管理的域。我有一个要添加的名为“test”的子域,但我希望它指向在我的服务器上运行的第二个网络服务器,端口为 8183。在 Cloudflare DNS 门户中,我有一个“test.example.com”的 A 记录,它指向到我的网络服务器的 IP 地址,该地址也被代理以隐藏我的网络服务器的实际 IP 地址。所有流量都通过 HTTPS 路由,证书也由 Cloudflare 提供。
我的 nginx default.conf:
# Redirect all traffic to HTTPS/443/SSL
server {
server_name example.com *.example.com;
listen 80;
return 301 https://$host$request_uri;
}
# example.com
server {
server_name example.com;
listen 443 ssl;
index index.php index.html;
ssl_certificate /etc/ssl/origincert.pem;
ssl_certificate_key /etc/ssl/privkey.key;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /website;
location ~ \.php$ {
autoindex on;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
# test.example.com -> proxy pass to 8183
server {
server_name test.example.com;
listen 443 ssl;
ssl_certificate /etc/ssl/origincert.pem;
ssl_certificate_key /etc/ssl/privkey.key;
location / {
proxy_pass http://MY_SERVER_IP_ADDRESS:8183;
}
}
但是,当我导航到 https://test.example.com 或 http 时,我只是重新路由到 https://example.com。我在我的服务器上安装了一个原始服务器证书,它安装并使用了example.com, *.example.com, and test.example.com。
【问题讨论】:
标签: nginx cloudflare nginx-reverse-proxy