nginx rewrite

Discussion in 'General' started by onastvar, Jul 30, 2012.

  1. onastvar

    onastvar Member

    I'm using the following nginx Directives in my ISPConfig for one of my websites where I run WordPress and it works fine.

    Code:
    location / {
                    try_files $uri $uri/ /index.php?$args;
               }
    
           # Add trailing slash to */wp-admin requests.
           rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
           location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
                    expires max;
                    log_not_found off;
           }
    # Deny public access to wp-config.php
    location ~* wp-config.php { 
        deny all; 
    }
    I'm trying to figure out how can I setup nginx rewrite so I can install another CMS (WordPress, Joomla, etc.) within same website, in another folder. Anyone has similar setup, please advise?
     
  2. falko

    falko Super Moderator Howtoforge Staff

    You can try nested locations for each folder, e.g. like this:

    Code:
    location / {
                    try_files $uri $uri/ /index.php?$args;
    
                   # Add trailing slash to */wp-admin requests.
                   rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
                   location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
                        expires max;
                        log_not_found off;
                   }
                   # Deny public access to wp-config.php
                   location ~* wp-config.php { 
                        deny all; 
                   }
    
    }
    Then try the same for a subfolder:

    Code:
    location /subfolder {
                    try_files $uri $uri/ /index.php?$args;
    
                   # Add trailing slash to */wp-admin requests.
                   rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    
                   location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
                        expires max;
                        log_not_found off;
                   }
                   # Deny public access to wp-config.php
                   location ~* wp-config.php { 
                        deny all; 
                   }
    
    }
     

Share This Page