nginx server configuration: subdomain to folder

前端 未结 4 1013
鱼传尺愫
鱼传尺愫 2021-02-02 13:49

I migrated from Apache 2 to nginx and I\'ve got problems to handly my subdomain control. What I want: When x.domain.tld is requested, internally rewrite to doma

4条回答
  •  故里飘歌
    2021-02-02 14:14

    This will work for www also.

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        index index.php index.html index.htm index.nginx-debian.html;
        server_name ~^www\.(?P.+)\.domain\.com$ ~^(?P.+)\.domain\.com$;
        root /var/www/html/$sub;
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    }
    

提交回复
热议问题