想法:
1.我想在云运行中运行部署在NGINX服务器上的静态站点。
1.此服务器将有两个子域-基本上,我希望将两个域分配给一个Cloud Run示例。
这样做的原因是在一个容器/云运行示例中有两个稍微不同的站点(因为它们只是稍微不同,所以拥有完全独立的服务似乎并不明智)。
问题是:
假设我有两个子域:www.example.com和sub2.example.com。我在我的nginx配置中描述了它们,看起来配置是正确的-服务器在容器中启动,我甚至可以访问其中一个子域(比如www.example.com)。但是当我尝试访问www.example.com时,我得到了一个500错误。我不认为这是我的nginx配置的问题, sub1.example.com and sub2.example.com. I described them both in my nginx config, seemingly the config is correct - the server starts up in the container and I can even reach one of the subdomains (let's say sub1.example.com). When I try to access sub2.example.com though, I get a 500 error. I do not think it is an issue with my nginx config, because the logs show something strange (obviously all the project info has been edited out by me):
{
"insertId": "63bfe64f00062b37157ff3d1",
"httpRequest": {
"requestMethod": "GET",
"requestUrl": "http://sub2.example.com/.well-known/acme-challenge/yjin9yFmV0NlXspNoP1_vLRP-0UBONJGPtl61l5I_gPuUsubDg2o88NS1GO8oA_Q",
"requestSize": "409",
"status": 500,
"responseSize": "814",
"userAgent": "Google-Certificates-Bridge",
"remoteIp": <remote-ip>,
"serverIp": <server-ip>,
"latency": "0.010053946s",
"protocol": "HTTP/1.1"
},
"resource": {
"type": "cloud_run_revision",
"labels": {
"service_name": "service-name",
"location": "europe-west1",
"project_id": "project-id",
"configuration_name": "configuration-name",
"revision_name": "revision-name"
}
},
"timestamp": "2023-01-12T10:51:59.404279Z",
"severity": "ERROR",
"labels": {
"instanceId": "0071bb48153ed55117f678f5d9609fe439a5eb69edd72da13aefdc58878f4c75f5b2345b96cf921b11f9f93e6833db2fa9339c9905b1de7ab8798984b4e121ca7f"
},
"logName": "projects/project-name/logs/run.googleapis.com%2Frequests",
"trace": "projects/project-name/traces/3548cd1a6ced04d963dc94419e208959",
"receiveTimestamp": "2023-01-12T10:51:59.676145078Z",
"spanId": "244873288111162464",
"traceSampled": true
}
问题是--到底发生了什么,我该如何处理才能达到预期的结果?
我的NGINX配置,以防万一:
server {
listen $PORT;
listen [::]:$PORT;
server_name sub1.example.com;
location / {
root /usr/share/nginx/html/sub1;
include /etc/nginx/mime.types;
try_files $uri /index.html;
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/sub1;
}
}
server {
listen $PORT;
listen [::]:$PORT;
server_name sub2.example.com;
location / {
root /usr/share/nginx/html/sub2;
include /etc/nginx/mime.types;
try_files $uri /index.html;
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/sub2;
}
}
1条答案
按热度按时间7nbnzgx91#
最后我用证书配置了一个负载平衡器,解决方案基本上是等到DNS完成它的传播,并制作适当的证书。我也不需要在云运行本身Map任何东西-我把两个子域都指向我的负载平衡器,并配置到我的应用程序的路由。错误本身就很愚蠢-我的第二个子域缺少
index.html
,我不喜欢这样,投500而不是404