nginx server configuration: subdomain to folder

前端 未结 4 1002
鱼传尺愫
鱼传尺愫 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:25

    I spent hours beating my head against the wall and this is what works for me

    server {
        listen       80;
    
        server_name ~^(?P.+)\.example\.com$; #<-- Note P before sub, it was critical for my nginx
        root /var/www/$sub; #<-- most important line cause it defines $document_root for SCRIPT_FILENAME
    
        location / {
                index index.php index.html; #<-- try_files didn't work as well
        }
    
        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000; #<-- probably you have another option here e.g. fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
                include        fastcgi_params;
        }
    }
    

提交回复
热议问题