WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Multiste in a subdirectory - nginx (4 posts)

  1. xanchez
    Member
    Posted 1 year ago #

    Hello Guys,

    I moved my sites from a shared hosting to a VPS (linode).
    Using a LEMP configuration (with Nginx and PHP-FPM) and have my 4 domains working fine.

    Except for 1 problem. In 1 domain i have an installation  of drupal in the root directory, and an installation of wordpress multisite in a subdirectory. This worked well with Apache, but i can't configure it properly with nginx.

    The drupal site is working fine. But the worpress site is not showing any file (css,js,jpg) from the template directory, just showing the text and files uploaded from posts or widgets. Also, i can't get into the administration panel, it gives me a 500 internal server error.

    I'm completly new to nginx so the problem must be is in my configuration file, maybe you guys can help me out:

    server {
       listen 80;
       server_name www.domain.tld;
       rewrite ^/(.*) http://domain.tld/$1 permanent;
    }
    server {
       listen 80;
       server_name domain.tld;
       access_log /home/username/public_html/domain.tld/log/access.log;
       error_log /home/username/public_html/domain.tld/log/error.log;
    
       location /
       {
          root /home/username/public_html/domain.tld/public;
          index index.php index.html;
          if (!-e $request_filename)
          {
             rewrite ^/(.*)$ /index.php?q=$1 last;
          }
       }
    
       location /subdomain
       {
          root /home/username/public_html/domain.tld/public/subdomain;
          index index.php index.html;
          rewrite /wp-admin$ $scheme://$host$uri/ permanent;
          rewrite ^.*/files/(.*)$ /subdomain/wp-includes/ms-files.php?file=$1 last;
    
          if (!-e $request_filename) {
             rewrite ^.+/?(/wp-.*) /subdomain/$1 last;
             rewrite ^.+/?(/.*\.php)$ /subdomain/$1 last;
             rewrite ^(.+)$ /subdomain/index.php?q=$1 last;
             rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ /subdomain/$1 last;
          }
       }
    
       location ~* ^/subdomain/.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
       {
          root /home/username/public_html/domain.tld/public/subdomain;
          rewrite ^/.+(/wp-.*/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ /subdomain/$1 last;
          rewrite ^.+/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ /subdomain/wp-includes/ms-files.php?file=$1 last;
          expires 30d;
          break;
       }
    
       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
       location ~ \.php$
       {
          fastcgi_pass 127.0.0.1:9000;
          fastcgi_index index.php;
          include /etc/nginx/fastcgi_params;
          fastcgi_param SCRIPT_FILENAME /home/username/public_html/domain.tld/public/$fastcgi_script_name;
       }
    }
  2. Out of curiosity, did Single Site work with pretty permalinks?

  3. xanchez
    Member
    Posted 1 year ago #

    Well, i moved the site already as multisite so i haven't tested it as single site.
    However, as multisite the pretty permalinks are working fine.
    My sites are working normally now, with this new configuration:

    server {
                listen 80;
                server_name www.domain.tld;
                return 301 http://domain.tld$request_uri;
           }
    server {
                listen 80;
                server_name domain.tld;
                access_log /home/username/public_html/domain.tld/log/access.log;
                error_log /home/username/public_html/domain.tld/log/error.log;
    
                location /
                {
                    root /home/username/public_html/domain.tld/public;
                    index index.php index.html;
                    try_files $uri $uri/ index.php?q=$uri&$args;
                }
    
                location /blogs
                {
                    root /home/username/public_html/domain.tld/public;
                    index index.php index.html;
    
                    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
                    rewrite ^.*/files/(.*)$ /blogs/wp-includes/ms-files.php?file=$1 last;
    
                    try_files $uri $uri/ @rewrites;
                }
                location @rewrites {
                   rewrite ^.+/?(/wp-.*) /blogs/$1 last;
                   rewrite ^.+/?(/.*\.php)$ /blogs/$1 last;
                   rewrite ^(.+)$ /blogs/index.php?q=$1 last;
                }
    
                # this prevents hidden files (beginning with a period) from being served
                location ~ /\.          { access_log off; log_not_found off; deny all; }
    
                # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
                location ~* \.php$
                {
                    location ~ \..*/.*\.php$ {return 404;}
                    fastcgi_pass 127.0.0.1:9000;
                    fastcgi_index index.php;
                    include /etc/nginx/fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME /home/username/public_html/domain.tld/public/$fastcgi_script_name;
                }
           }

    I'm sure this is not optimal, so I hope someone can help me optimize it.
    Now, i'll try to figure out how to make the cache plugin works.

  4. I've only been using nginx for 2 days ;) I'm not quite as snappy as I am with .htaccess yet.

Topic Closed

This topic has been closed to new replies.

About this Topic