我有两个物理服务器运行在同一个局域网上。两者都在运行webserver;一个运行apache2,另一个运行nginx。它们各自都有不同的域名,但具有相同的外部广域网IP地址。假设网络布局如下:
WAN
10.20.30.40
|----------|----------|
| |
Domain 1 Domain 2
exampleABC.com (sub.)exampleXYZ.com
| |
|----------|----------|
|
Single LAN
|
|----------|----------|
| |
IP addr 1 IP addr 2
192.168.0.10 192.168.0.20
| |
| |
Server 1 Server 2
apache2 nginxapache2服务器属于我,而nginx服务器不属于我。这两台服务器为它们提供的每一项服务都有专门的子域--例如,(www.)exampleABC.com用于主网页,cloud.exampleXYZ.com用于反向代理云服务,media.exampleXYZ.com用于媒体等等。
由于未知的原因,在连接到广域网IP地址时,nginx服务器是优先的--最初,这两个域将导致nginx托管的主网页,但使用以下(当前) nginx配置,exampleABC.com将正确地引导到apache2服务器,而exampleXYZ.com将继续引导nginx服务器。
server {
listen 80;
# listen on all subdomains
server_name exampleABC.com *.exampleABC.com;
location / {
# transparently proxy to other server (port 443)
proxy_pass http://192.168.0.10:80;
# set "Host" header passed to other server to client-requested FQDN so other server knows which subdomain is being requested
proxy_set_header Host $http_host;
}
}
server {
listen 443 ssl;
server_name exampleABC.com *.exampleABC.com;
location / {
proxy_pass https://192.168.0.10:443;
proxy_set_header Host $http_host;
}
}但是,apache2服务器承载的子域(docs.exampleABC.com等)继续连接到nginx。( nginx子域运行良好。)
下面是我通过apache2设置的子域配置之一:
ServerName ft.exampleABC.com
Redirect permanent / https://ft.exampleABC.com/
RewriteEngine on
RewriteCond %{SERVER_NAME} =ft.exampleABC.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName ft.exampleABC.com
#ServerAlias *.exampleABC.com
ServerAdmin webmaster@localhost
DocumentRoot /mnt/external/webserver/ft
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
< snipped: lines added by certbot >
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet我希望在连接到exampleABC.com、ft.exampleABC.com等时,客户端能够正确地连接到apache2服务器。当然,exampleXYZ.com及其子域仍然应该连接到nginx服务器。
其他资料:
最初,客户端(如web浏览器)无法验证exampleABC.com的TLS证书的真实性。(请注意,我在apache2下正确设置了TLS证书。)这是通过将我的apache2域添加到nginx服务器的证书来解决的。不过,我不认为这是必要的-我的证书(在apache2下)应该通过反向代理传递,不是吗?
如果我尝试通过curl连接到apache2服务器,同时手动指定主机头(通过curl -vL -H "Host: ft.exampleABC.com" https://192.168.0.10),我将被重定向到nginx服务器的主网页。我不知道这意味着什么。
编辑:
根据nginx系统的系统管理员,这是nginx -T的输出:
另外,nginx服务器通过LinuxServer.io的“搜索”在容器中运行。
编辑:
IoLinuxServer.io将加载与默认配置不同的nginx配置。下面的命令获得正确的conf:
docker exec -it swag /usr/sbin/nginx -c /config/nginx/nginx.conf -T所述命令的结果可在这种糊状中找到。(StackExchange字符太多)
发布于 2022-03-20 16:52:24
起作用的是创建一个新文件/config/nginx/proxy-confs/exampleABC.subdomain.conf (等效于/etc/nginx/conf.d/exampleABC.subdomain.conf,exampleABC.subdomain与任何东西都是可替换的),其内容如下:
server {
listen 80;
listen [::]:80;
server_name .exampleABC.com;
location / {
proxy_pass http://192.168.0.10:80;
proxy_set_header Host $http_host;
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name .exampleABC.com;
location / {
proxy_pass https://192.168.0.10:443;
proxy_set_header Host $http_host;
}
}我在最初的文章中输入的nginx配置应该与此功能几乎相同,因此我怀疑问题要么是缺乏listen [::]:;来实现IPv6兼容性,要么是一些与我创建的配置文件冲突的配置文件。
发布于 2022-02-19 16:35:58
我是他们服务器所在的房子的主人。我一点也不是专家,我只是很好地跟随导游。我有一个DuckDNS域名,我为Plex、Sonarr、SABnzbd等运行,我还为我的反向代理运行了一个SWAG容器。
Unilock引进了他们自己的服务器。它有自己的域名,所有服务器都使用apache2。这台服务器在我的网络上之前,正在监听与我的(80,443等)相同的端口。
我被告知,如果Unilock可以在非标准端口上运行他们的服务,我们就可以改变我的pfSense路由器的设置来运行这两台服务器。我还被告知我可以将他们服务器的域名添加到我的EXTRA_DOMAINS容器的变量中。我这么做了,但没什么用。
我还在我的SITE_CONF默认文件中添加了一个额外的服务器块。额外的块如下所示:
#second server block
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name ; #change this to your subdomain
#include /config/nginx/ssl.conf;
client_max_body_size 0;
location / {
#include /config/nginx/proxy.conf;
resolver 127.0.0.11 valid=30s;
#set $upstream_app 192.168.0.10;
#set $upstream_port 443;
#set $upstream_proto https;
#proxy_pass $upstream_proto://$upstream_app:$upstream_port;
proxy_pass https://192.168.0.10:443;
proxy_max_temp_file_size 2048m;
}我的主服务器块是默认文件。如果我需要发布整个配置,我会的;尽管它似乎已经在Pastebin上这样做了。输入上述内容后,我可以访问单边号的主页面,但是它们的子域仍然重定向到默认的nginx服务器起始页面。
https://serverfault.com/questions/1093483
复制相似问题