nginx server configuration: subdomain to folder

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

    You should take a look at http://wiki.nginx.org/IfIsEvil. You're doing a whole lot wrong in this configuration file.

    server {
        server_name domain.tld www.domain.tld;
    
        location / {
            try_files $uri /index.php;
        }
    
        location ~ \.php {
            include fastcgi_params;
            fastcgi_pass  unix:/etc/nginx/sockets/domain.socket;
        }
    }
    
    server {
        server_name "~^(?.+)*\.(?.*)$";
        return 301 $scheme://$domain/$sub$request_uri;
    }
    

    If what you want is to keep that internal, you won't be able to rewrite it. By definition, a cross site rewrite needs to be sent back to the browser. You'll have to proxy the request.

    server {
        server_name "~^(?.+)*\.(?.*)$";
        proxy_pass http://$domain/$sub$request_uri;
    }
    

    You should read the Nginx wiki. All of this is explained in depth.

提交回复
热议问题