子域名作为子文件夹和符号链接

子域名作为子文件夹和符号链接

我有一个主 wordpress 和几个子域。它们是以通常的方式创建的 - 我将子域添加到面板(Fastpanel),并在子域文件夹中添加了指向主域文件的符号链接。它按预期完美运行。但问题是,添加 100 个相同的子域并创建新站点确实不太方便。

我决定尝试将子域添加为文件夹。现在它看起来像这样example.com/sub1 example.com/sub2。如果添加一些文件(例如,index.html带有文本) - 可以正确打开。但我添加了符号链接,然后被重定向到主站点example.com。可能需要对配置进行一些操作。我将不胜感激任何有关此事的帮助。

现在面板生成的我的配置如下所示:


server {
    server_name example.com *.example.com;
    listen xxx.xxx.xx.xx:443 ssl  http2 ;

    add_header Strict-Transport-Security "max-age=31536000" always;

    charset utf-8;

    gzip on;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/css text/xml application/javascript text/plain application/json image/svg+xml image/x-icon;
    gzip_comp_level 5;

    set $subdomain "";
    if ($host ~* ^([a-z0-9-\.]+)\.example.com) {
        set $subdomain $1;
    }
    if ($host ~* ^www.example.com) {
        set $subdomain "";
    }
    
    set $root_path /var/www/example.com/data/www/example.com/$subdomain;
    

    root $root_path;
    disable_symlinks off;

    location / {
        index index.php;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/example.com.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
     }

    location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpeg|avi|zip|gz|bz2|rar|swf|ico|7z|doc|docx|map|ogg|otf|pdf|tff|tif|txt|wav|webp|woff|woff2|xls|xlsx|xml)$ {
        try_files $uri $uri/ /index.php?$args;
        expires 180d;
    }

    location @fallback {
        fastcgi_pass unix:/var/run/example.com.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
    }

    include "/etc/nginx/fastpanel2-sites/example.com/example.com.includes";
    include /etc/nginx/fastpanel2-includes/*.conf;

}


server {
     server_name example.com;

    listen 194.58.108.206:80;
    listen [2a00:f940:2:4:2::235f]:80;

    return 301 https://$host$request_uri;

}


server {
    server_name www.example.com *.example.com;
    listen xxx.xxx.xx.xx:80;
    listen xxx.xxx.xx.xx:443 ssl http2 ;

    add_header Strict-Transport-Security "max-age=31536000" always;
    return 301 $scheme://example.com$request_uri;

}

任务是相同的 - 主站点应在所有子域上打开,但子域的地址应保存,即必须按原样sub1.example.com打开。 无需重定向到主站点。example.com

相关内容