Need help with Nginx rules for Wp multisite

Discussion in 'Installation/Configuration' started by IM NetworkSolutions, Mar 3, 2015.

  1. IM NetworkSolutions

    IM NetworkSolutions New Member

    I have a server successfully setup using this guide:
    https://www.howtoforge.com/perfect-server-debian-wheezy-nginx-bind-dovecot-ispconfig-3
    I have also installed a wordpress website on it and my goal is to transform this one to a Multi Wordpress.
    The website was formally hosted on a Vestacp server as a wordpress multisite.
    I have searched everywhere for a ruleset that works with wordpress multisite in subcategories with domain mapping and have not found any working one.
    I also wants to use wp supercache or w3total cache with this setup for performance improvements.

    Anyone know how to make this happen?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    If you dont find a working rulset, then you can try to take the apache ruleset from the .htaccess file and use a nginx rule converter to get a base rule set which you might hav to finetune then.
     
  3. IM NetworkSolutions

    IM NetworkSolutions New Member

    I think I have it sorted, my problem though is that I need to use phpmyadmin and webmail from main server address like so:
    server1.example.com/phpmyadmin & server1.example.com/webmail.
    this is due to that I use multiwordpress and accounts I add needs email.
    I can add a new email domain and make addresses from that but I can't login with:
    emaildomain.com/webmail.

    Or have I misssed something?
    Maybe you know any solutions to that?
    I'm talking about a nginx rule to add to optios tab in ispconfig or do I have to add it somewhere else?
     
  4. IM NetworkSolutions

    IM NetworkSolutions New Member

    I think I have found some problems..
    It seems I have to use http and not https for the /phpmyadmin and /webmail
    when using :
    The error message i get is either 404 or safe connection failed due to : ssl_error_rx_record_too_long
    That is not good. How do I manage to make the links secured with https?


    Also when using domain mapping in wordpress and adding a link I only see the generic nginx page when going to the mapped domain..
    Any Idea on what to do to correct this?
    I tried to add a Alias domain but that redirected the main website also to the new domain.
    and when going to main domain I get error due to to many redirects
     
    Last edited: Mar 5, 2015
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    Add ssl certificates to the nginx apps vhost file.

    You hav to add an aliasdomain without an redirect, just the alias domain and no additional redirect settings.
     
  6. IM NetworkSolutions

    IM NetworkSolutions New Member

    Okey, I seems to have it working now, thanks!
    I have a new set of problems though..
    I have tried to upload a wp theme I have worked on to my installation and I get:
    "Nginx error: 413 request entity to large. I tried to solve the problem with this thread:
    https://www.howtoforge.com/community/threads/413-request-entity-too-large-nginx.68628/#post-326114
    After restarting the server I get:
    Error 500: Internal Server Error when trying to go to /wp-admin and /wp-login

    Any Idea on how to solve this problem?
    Where do I check to see the error regarding what might be wrong?
     
  7. till

    till Super Moderator Staff Member ISPConfig Developer

    Please post the nginx diective sthat yu entered into the nginx directives field of the website.

    The error.log of the website.
     
  8. IM NetworkSolutions

    IM NetworkSolutions New Member

    I do not have any errors regarding this 500 problem.
    When logging in through a different website in the network with my superadmin credentials I can reach the network admin dashboard but not through my main website..
    Any ideas on how that is possible?
     
  9. till

    till Super Moderator Staff Member ISPConfig Developer

    If there is no error in the log, then it is likely that you access a different server or a different vhost / website on this server. Did you check the global apache error.log too?
     
  10. IM NetworkSolutions

    IM NetworkSolutions New Member

    My server is nginx based and I seems to have solved the problem with login to my network panel in wordpress.
    My problem I am struggling with now is that I do not seem to manage to have webmail and phpmyadmin over ssl.
    when going to my server I can only reach the /webmail and /phpmyadmin over unsecure link as following:

    http://server1.example.com:8081/squirrelmail/src/webmail.php
    and
    http://server1.example.com:8081/phpmyadmin
    how do I solve it so that I will reach them with https:// instead?

    My nginx Directives is:

    Code:
    location /squirrelmail {
                   root /usr/share/;
                   index index.php index.html index.htm;
                   location ~ ^/squirrelmail/(.+\.php)$ {
                           try_files $uri =404;
                           root /usr/share/;
                           fastcgi_pass unix:/var/run/php5-fpm.sock;
                           fastcgi_param HTTPS $https; # <-- add this line
                           fastcgi_index index.php;
                           fastcgi_param SCRIPT_FILENAME $request_filename;
                           include /etc/nginx/fastcgi_params;
                           fastcgi_param PATH_INFO $fastcgi_script_name;
                           fastcgi_buffer_size 128k;
                           fastcgi_buffers 256 4k;
                           fastcgi_busy_buffers_size 256k;
                           fastcgi_temp_file_write_size 256k;
                           fastcgi_intercept_errors on;
                   }
                   location ~* ^/squirrelmail/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                           root /usr/share/;
                   }
            }
            location /webmail {
                   rewrite ^/* /squirrelmail last;
            }
    location /cgi-bin/mailman {
                   root /usr/lib/;
                   fastcgi_split_path_info (^/cgi-bin/mailman/[^/]*)(.*)$;
                   include /etc/nginx/fastcgi_params;
                   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                   fastcgi_param PATH_INFO $fastcgi_path_info;
                   fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                   fastcgi_intercept_errors on;
                   fastcgi_pass unix:/var/run/fcgiwrap.socket;
            }
    
            location /images/mailman {
                   alias /usr/share/images/mailman;
            }
    
            location /pipermail {
                   alias /var/lib/mailman/archives/public;
                   autoindex on;
            }
    location /phpmyadmin {
                   root /usr/share/;
                   index index.php index.html index.htm;
                   location ~ ^/phpmyadmin/(.+\.php)$ {
                           try_files $uri =404;
                           root /usr/share/;
                           fastcgi_pass unix:/var/run/php5-fpm.sock;
                           fastcgi_param HTTPS on; # <-- add this line
                           fastcgi_index index.php;
                           fastcgi_param SCRIPT_FILENAME $request_filename;
                           include /etc/nginx/fastcgi_params;
                           fastcgi_param PATH_INFO $fastcgi_script_name;
                           fastcgi_buffer_size 128k;
                           fastcgi_buffers 256 4k;
                           fastcgi_busy_buffers_size 256k;
                           fastcgi_temp_file_write_size 256k;
                           fastcgi_intercept_errors on;
                   }
                   location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                           root /usr/share/;
                   }
            }
            location /phpMyAdmin {
                   rewrite ^/* /phpmyadmin last;
            }
    # Secure nginx.conf file
    location /nginx.conf {
    deny all;
    }
    
    # Support permalinks
    location / {
    try_files $uri $uri/ /index.php?$args;
    }
    
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires max;
    log_not_found off;
    }
    
    rewrite ^/files/(.+) /wp-includes/ms-files.php?file=$1 last;
    location ^~ /files/ {
    rewrite ^.*/files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
    }
    
    # Rewrite multisite '.../wp-.*' and '.../*.php'.
    if (!-e $request_filename) {
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
    }
    What do I need to change to solve my problems?
     
  11. till

    till Super Moderator Staff Member ISPConfig Developer

    Add a ssl cert to the apps vhost config file.
     
  12. IM NetworkSolutions

    IM NetworkSolutions New Member

    I again have problems with the mapped domain in wordpress multisite..
    I do not know if the rules are to blame or cloudflare?
    I use cloudflare dns control and do not use the dns part in ispconfig.
    My nginx directives are as stated above and I seem to have all kinds of problems..
    Would sure like some help with rules for both wordpress multisite setup and also to setup webmail and phpmyadmin. I only need these rules for the main domain.

    What I have done is:

    1. Add Main domain as site in ispconfig control panel
    2. installed Wordpress and activated the multisite part as instructed in wordpress website
    3. setup all pages and everything on main domain.
    4. added this ruleset to main domain site:
      Code:
      location /squirrelmail {
                     root /usr/share/;
                     index index.php index.html index.htm;
                     location ~ ^/squirrelmail/(.+\.php)$ {
                             try_files $uri =404;
                             root /usr/share/;
                             fastcgi_pass unix:/var/run/php5-fpm.sock;
                             fastcgi_param HTTPS $https; # <-- add this line
                             fastcgi_index index.php;
                             fastcgi_param SCRIPT_FILENAME $request_filename;
                             include /etc/nginx/fastcgi_params;
                             fastcgi_param PATH_INFO $fastcgi_script_name;
                             fastcgi_buffer_size 128k;
                             fastcgi_buffers 256 4k;
                             fastcgi_busy_buffers_size 256k;
                             fastcgi_temp_file_write_size 256k;
                             fastcgi_intercept_errors on;
                     }
                     location ~* ^/squirrelmail/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                             root /usr/share/;
                     }
              }
              location /webmail {
                     rewrite ^/* /squirrelmail last;
              }
      location /cgi-bin/mailman {
                     root /usr/lib/;
                     fastcgi_split_path_info (^/cgi-bin/mailman/[^/]*)(.*)$;
                     include /etc/nginx/fastcgi_params;
                     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                     fastcgi_param PATH_INFO $fastcgi_path_info;
                     fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                     fastcgi_intercept_errors on;
                     fastcgi_pass unix:/var/run/fcgiwrap.socket;
              }
      
              location /images/mailman {
                     alias /usr/share/images/mailman;
              }
      
              location /pipermail {
                     alias /var/lib/mailman/archives/public;
                     autoindex on;
              }
      location /phpmyadmin {
                     root /usr/share/;
                     index index.php index.html index.htm;
                     location ~ ^/phpmyadmin/(.+\.php)$ {
                             try_files $uri =404;
                             root /usr/share/;
                             fastcgi_pass unix:/var/run/php5-fpm.sock;
                             fastcgi_param HTTPS on; # <-- add this line
                             fastcgi_index index.php;
                             fastcgi_param SCRIPT_FILENAME $request_filename;
                             include /etc/nginx/fastcgi_params;
                             fastcgi_param PATH_INFO $fastcgi_script_name;
                             fastcgi_buffer_size 128k;
                             fastcgi_buffers 256 4k;
                             fastcgi_busy_buffers_size 256k;
                             fastcgi_temp_file_write_size 256k;
                             fastcgi_intercept_errors on;
                     }
                     location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                             root /usr/share/;
                     }
              }
              location /phpMyAdmin {
                     rewrite ^/* /phpmyadmin last;
              }
      # Secure nginx.conf file
      location /nginx.conf {
      deny all;
      }
      
      # Support permalinks
      location / {
      try_files $uri $uri/ /index.php?$args;
      }
      
      rewrite /wp-admin$ $scheme://$host$uri/ permanent;
      location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
      expires max;
      log_not_found off;
      }
      
      rewrite ^/files/(.+) /wp-includes/ms-files.php?file=$1 last;
      location ^~ /files/ {
      rewrite ^.*/files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
      }
      
      # Rewrite multisite '.../wp-.*' and '.../*.php'.
      if (!-e $request_filename) {
      rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
      rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
      }
    5. add a new website in wordpress network admin.
    6. add a aliasdomain in ispconfig with no redirects or other rules added
    7. installed domain mapping plugin and moved sunrise.php to designated are with filezilla
    8. added a domain in domain mapping and also add my main IP address in domain mapping dashboard
    My problem right now are:
    1. When going to mapped domain or even the regular address maindomain.tld/Newwebsite I get a 500 error message from nginx
    2. When trying to go to wp dashboard for the new website I get 500 internal error
    3. when trying to go to maindomain/webmail or maindomain/phpmyadmin I get 500 intenal server error
    4. when going to sever1.maindomain.tld:8081/webmail with https:// infront I get ssl error
    So I do not know where to start here, relly need some help to sort this out..
    Please!!:(
     
  13. IM NetworkSolutions

    IM NetworkSolutions New Member

    I have checked the vhost file for my main website and it looks like this:
    Code:
    server {
            listen *:80;
    
            listen *:443 ssl;
                    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_certificate /var/www/clients/client0/web1/ssl/mainsite.com.crt;
            ssl_certificate_key /var/www/clients/client0/web1/ssl/mainsite.com.key;
    
            server_name mainsite.com *.mainsite.com www.subdirsite1.com subdirsite1.com;
    
            root   /var/www/mainsite.com/web;
    
    
    
            index index.html index.htm index.php index.cgi index.pl index.xhtml;
    
    
    
            error_page 400 /error/400.html;
            error_page 401 /error/401.html;
            error_page 403 /error/403.html;
            error_page 404 /error/404.html;
            error_page 405 /error/405.html;
            error_page 500 /error/500.html;
            error_page 502 /error/502.html;
            error_page 503 /error/503.html;
            recursive_error_pages on;
            location = /error/400.html {
    
                internal;
            }
            location = /error/401.html {
    
                internal;
            }
            location = /error/403.html {
    
                internal;
            }
            location = /error/404.html {
    
                internal;
            }
            location = /error/405.html {
    
                internal;
            }
            location = /error/500.html {
    
                internal;
            }
            location = /error/502.html {
    
                internal;
            }
            location = /error/503.html {
    
                internal;
            }
    
            error_log /var/log/ispconfig/httpd/mainsite.com/error.log;
            access_log /var/log/ispconfig/httpd/mainsite.com/access.log combined;
    
            location ~ /\. {
                deny all;
                access_log off;
                log_not_found off;
            }
    
            location = /favicon.ico {
                log_not_found off;
                access_log off;
            }
    
            location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
            }
    
            location /stats/ {
    
                index index.html index.php;
                auth_basic "Members Only";
                auth_basic_user_file /var/www/clients/client0/web1/web/stats/.htpasswd_stats;
            }
    
            location ^~ /awstats-icon {
                alias /usr/share/awstats/icon;
            }
    
            location ~ \.php$ {
                try_files /0081da899541841e79823d9e96f7c350.htm @php;
            }
    
            location @php {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                fastcgi_pass unix:/var/lib/php5-fpm/web1.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
              }
    
            location /cgi-bin/ {
                try_files $uri =404;
                include /etc/nginx/fastcgi_params;
                root /var/www/clients/client0/web1;
                gzip off;
                fastcgi_pass  unix:/var/run/fcgiwrap.socket;
                fastcgi_index index.cgi;
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
            }
    
    
    
            location /nginx.conf {
            deny all;
            }
    
            location / {
            try_files $uri $uri/ /index.php?$args;
            }
    
            rewrite /wp-admin$ $scheme://$host$uri/ permanent;
            location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
            }
    
            rewrite ^/files/(.+) /wp-includes/ms-files.php?file=$1 last;
            location ^~ /files/ {
            rewrite ^.*/files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
            }
    
            if (!-e $request_filename) {
            rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
            rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
            }
    
    
    }
    
    I do not know where the problem is, anyone know?
     
  14. IM NetworkSolutions

    IM NetworkSolutions New Member

    I seems to have fixed most of the problems myself but I still have one problem..
    When mapping a domain in wordpress and going to mapped domain I get the generic nginx page.
    When going to https://mappeddomain.ltd I can view the website as normal but when going to the same domain without https:// infront I just get the generic nginx page.
    Any suggestion on how to solve this?
     

Share This Page