1

I have a main wordpress and several subdomains. They were created in the usual way - I added subdomains to the panels (Fastpanel), and in the subdomain folders I added symbolic links to the files of the main domain. It works perfectly as expected. But the question arose about adding 100 of the same subdomains and creating new sites is not really very convenient.

I decided to try adding subdomains as folders. Now it looks like this example.com/sub1 example.com/sub2 . If add some file, for example, index.html with text - opens correctly. But I add symbolic links and I am redirected to the main site example.com. Probably something needs to be done with the config. I will be grateful for any help in this matter.

Now my config generated by the panel looks like this:


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;

}

The task is the same - the main site should be opened on all subdomains, but the address of the subdomain should be saved, i.e. at sub1.example.com must open example.com as it is. Without redirecting to the main site.

  • Why are you not using a [multisite installation](https://wordpress.org/support/article/create-a-network/)? – Gerald Schneider Nov 06 '21 at 12:07
  • The only change I need on subdomains is the name of the city. Multisite is heavy, creates a bunch of tables in the database, creates duplicate folders with files that take up space. Bad solution for my problem, already tried) – Sergey Pervushin Nov 06 '21 at 12:17

0 Answers0