DDEV:使用nginx-fpm和各个域将HTTP重定向到HTTP
我正在将生产中的一些小型网站移至DDEV,其中一些网站有多个域,并将301重定向到主HTTPS网站。
当我使用.conf文件来管理应以这种方式重定向到主站点的域时,此配置与“天然” Nginx合作良好:
server {
listen 80;
server_name .domain1.com
.domain2.com
.domain3.com
;
return 301 https://www.maindomain.com;
}
我尝试创建一个新domains.conf文件并将其添加.ddev/nginx_full目录要在重新启动过程中加载,但似乎NGINX无法识别该文件。
在主要的“天然” nginx配置文件中,我有此服务器将所有来自http的请求重定向到https:
server {
listen 80;
access_log off;
error_log off;
server_name maindomain.com www.maindomain.com;
return 301 https://www.$host$request_uri;
}
我尝试在.ddev/nginx_full/nginx-site.conf文件中添加这些配置有时进行无限的重定向,有时不认识域。
在config.yaml文件中,我有:
additional_fqdns:
- domain1.com
- domain2.com
- domain3.com
- maindomain.com
- www.maindomain.com
use_dns_when_possible: false
我敢肯定,这是处理这种情况的“正确方法”,但是,查看文档,我没有找到并为此回答。这样,我问这里有人是否有抓住。
多谢
I'm moving some small websites in production to DDEV and, some of them has multiple domains with a 301 redirection to the main HTTPS site.
This config was working well with the "natural" Nginx when I was using a .conf file to manage the domains that should be redirect to the main site on this way:
server {
listen 80;
server_name .domain1.com
.domain2.com
.domain3.com
;
return 301 https://www.maindomain.com;
}
I tried to create a new domains.conf file and add it inside the .ddev/nginx_full directory to be loaded in the restart process but seems the Nginx didn't recognize such file.
In the main "natural" Nginx config file I has this server to redirect all requests coming from HTTP to HTTPS:
server {
listen 80;
access_log off;
error_log off;
server_name maindomain.com www.maindomain.com;
return 301 https://www.$host$request_uri;
}
I tried to add these configs inside the .ddev/nginx_full/nginx-site.conf file but the server start to be crazy, doing sometimes infinite redirections and sometimes, not recognize the domains.
Inside the config.yaml file I have:
additional_fqdns:
- domain1.com
- domain2.com
- domain3.com
- maindomain.com
- www.maindomain.com
use_dns_when_possible: false
I'm sure that's a "right way" to handle this situation but, looking the docs, I didn't find and answer for that. On this way, I ask if someone here have the catch for that.
Thanks a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这对您有用。
使用以下内容添加文件.ddev/nginx/redirect.conf:
这使用a ddev nginx摘要,也可以使用完整的nginx配置来完成。
I think this will work for you.
Add the file .ddev/nginx/redirect.conf with these contents:
This uses a DDEV nginx snippet, it could also be done with a full nginx config.
DDEV-ROUTER充当终止SSL/443的反向代理,并将端口80的请求传递到Web容器。
您会看到无限重定向,因为它始终在端口80上看到请求。
The ddev-router acts as a reverse proxy that terminates SSL/443 and passes along requests on port 80 to the web container.
You see the infinite redirects because it sees the request always on port 80.