Laravel Forge将通配符子域添加到现有域 [英] Laravel Forge Add Wildcard Subdomain to Existing
问题描述
如何将通配符子域添加到已经创建的站点?我知道当您第一次创建一个复选框时,您可以选中一个复选框,但是事后该如何做呢?我需要编辑NGINX Config文件吗?
How do I add Wildcard Subdomains to a site I already created? When you first create one I know you can check a box but how do you do so after the fact? Do I have to edit the NGINX Config file?
我厌倦了将其放置在 server {}
部分中: server_name〜^(.*)\.mydomain \ .com $;
,但是没有用.我一直使用.htaccess,所以我对NGINX不太熟悉
I tired placing this in the server{}
section: server_name ~^(.*)\.mydomain\.com$ ;
but it didnt work. I have always used .htaccess so I am not too familiar with NGINX
我尝试过的NGINX配置文件
NGINX Config File I tried
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name mydomain.com;
server_name ~^(.*)\.mydomain\.com$
root /home/forge/mydomain.com/public;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/mydomain.com/321141/server.crt;
ssl_certificate_key /etc/nginx/ssl/mydomain.com/321141/server.key;
MORE BELOW
如果我访问 mydomain.com
,我会得到我的网站,但是如果我访问app.mydomain.com,则会得到服务器IP地址.
.在我的本地环境中,我有子域路由,因此当我用代客转入该子域时,它可以工作.
if I go to mydomain.com
I get my site, but if I go to app.mydomain.com I get server IP address could not be found.
. On my local environment I have sub domain routing so when I go to that subdomain with Valet it works.
推荐答案
要使其正常工作,您需要做两件事:
Okay for it to work you need to do 2 things:
首先,在DNS上设置A记录,使其主机为 *
,并指向您的服务器IP
First, set up your A record on your DNS so its host is *
and it points to your server IP
然后,在您的NGINX配置文件中,只需更改站点即可:
Then, in your NGINX config file for the site you just need to change:
server_name mydomain.com;
到
server_name .mydomain.com;
在域名前注意.
.然后,它应该可以工作(DNS可能需要一点时间来识别它,但是可以工作).
Notice the .
before the domain name. It should then work (might take a little time for the DNS to recognize it, but worked).
这篇关于Laravel Forge将通配符子域添加到现有域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!