0
votes

I have set up my main WordPress site on Nginx and /demos/ subdirectory have a multisite network.

site.com [main site]

site.com/demos/ [multisite]

site.com/demos/theme1 [subsite]

site.com/demos/theme2 [subsite]

nginx is configured and working fine for the main site but for multisite, It is returning me 404.

multisite can work with subdomain configuration. Is there a way we could make it work with subdirectory way?

1
I'm not sure what you mean by Is there a way we could make it work with subdirectory way?, but you can tell Nginx to listen on a subdomain and serve that subdomain with content from one of your sub-directory. Is that what you looking for? - Praveen Premaratne
@PraveenP No. I know I can setup it with subdomains configuration in nginx. I am looking for a way to do it without subdomains configuration. - hiddenpearls

1 Answers

0
votes

You should look into Trellis it allows you to configure multi-sites and multi-tenanted WordPress sites and it configures the Nginx for you using a simple config file. The only catch is its subdomain based and you'll need to tinker around a bit with the generated config.

Here's my suggestion

Nginx support multiple location within server{} blocks configuration which could be what you're looking for.

# This block redirects all request from HTTP to HTTPS without losing any arguments or parameters
server {
        listen 80;
        server_name site.com;
#       root /var/www/html;
        return 301 https://$server_name$request_uri;
        location / {
               return 301 https://$server_name$request_uri;
        }
}

server {
        listen 443 ssl;
        server_name site.com;

        location /demos/theme1/ {
                root /var/www/html/demos/theme1;
                client_max_body_size 100M;
        }

        location /demos/theme2/ {
                root /var/www/html/demos/theme2;
                client_max_body_size 100M;
        }

        #    listen 443 ssl; # managed by Certbot
        ssl_certificate /path/to/fullchain.pem;
        ssl_certificate_key /path/to/privkey.pem;
        ssl_session_cache shared:le_nginx_SSL:1m;
        ssl_session_timeout 1440m;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256 ECDHE-ECDSA-AES256-GCM-SHA384 ECDHE-ECDSA-AES128-SHA ECDHE-ECDSA-AES256-SHA ECDHE-ECDSA-AES128-SHA256 ECDHE-ECDSA-AES256-SHA384 ECDHE-RSA-AES128-GCM-SHA256 ECDHE-RSA-AES256-GCM-SHA384 ECDHE-RSA-AES128-SHA ECDHE-RSA-AES128-SHA256 ECDHE-RSA-AES256-SHA384 DHE-RSA-AES128-GCM-SHA256 DHE-RSA-AES256-GCM-SHA384 DHE-RSA-AES128-SHA DHE-RSA-AES256-SHA DHE-RSA-AES128-SHA256 DHE-RSA-AES256-SHA256 EDH-RSA-DES-CBC3-SHA";


}

Then save this into a file with .conf extension (/etc/nginx/sites-available/site.conf) in the /etc/nginx/sites-availabe/ and create a symbolic link to that file in /etc/nginx/sites-enabled/ folder as Nginx recommended. But you can place the file directly in the /etc/nginx/sites-enabled/ folder and forget symbolic links.

You should use one file per domains (multi-site) so its easier to bugfix as one bugged config file may takedown the Nginx with 500 - Internal server error or 502 - Bad Gateway

This is a workaround for your scenario but it's really messy, so source control is recommended.

If the multi-sites has their own domains you should configure each multi-site in their own config file.