Laravel Forge Add Wildcard Subdomain to Existing

让人想犯罪 __ 提交于 2021-02-07 10:24:46

问题


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?

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 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

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.


回答1:


Okay for it to work you need to do 2 things:

First, set up your A record on your DNS so its host is * and it points to your server IP

Then, in your NGINX config file for the site you just need to change:

server_name mydomain.com;

to

server_name .mydomain.com;

Notice the . before the domain name. It should then work (might take a little time for the DNS to recognize it, but worked).



来源:https://stackoverflow.com/questions/49313076/laravel-forge-add-wildcard-subdomain-to-existing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!