CB2 + Nginx + protect directory = duplicate location "/"

shafie

Verified User
Joined
Jan 9, 2012
Messages
14
Hi,
settings: CB2+Nginx+PHP-FPM

In my server I have several Wordpress instalations and I want to use permalink as I was using with apache. so I edited the file /usr/local/directadmin/data/templates/nginx_server.conf to add this location:
Code:
location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                #http://wiki.nginx.org/Wordpress
                try_files $uri $uri/ /index.php?$args;
               }

All went OK until I added a protected directory and I choosed the public_html directory, so in the nginx.conf I had 2 locations with the root, and it raised an error.
The new code in nginx is:
Code:
location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                # http://wiki.nginx.org/Wordpress
                try_files $uri $uri/ /index.php?$args;
        }
                # use fastcgi for all php files
                location ~ \.php$
                {
                        try_files $uri =404;
                        fastcgi_split_path_info ^(.+\.php)(/.+)$;
                        include /etc/nginx/fastcgi_params;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include /etc/nginx/nginx_limits.conf;

                        if (-f $request_filename)
                        {
                                fastcgi_pass unix:/usr/local/php55/sockets/exampledomain.sock;
                        }
                }



        location  /  {
                auth_basic              "members";
                auth_basic_user_file    /home/admin/domains/exampledomain.com/.htpasswd/public_html/.htpasswd;
        }

How I could add the location "/" to a custom nginx_server.conf and doesn't crash with the nginx_protected_directory.conf
 
I have solved it by my self.

  1. I have copied the file nginx_server.conf to /usr/local/directadmin/data/templates/custom/nginx_server.conf
  2. Edit the file nginx_server.conf and add the line (without location)

Code:
try_files $uri $uri/ /index.php?$args;

Final result of the file nginx_server.conf:

Code:
|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html|
|?REALDOCROOT=`HOME`/domains/`DOMAIN`/public_html|
|?OPEN_BASEDIR_PATH=`HOME`/:/tmp:/var/tmp:/usr/local/lib/php/|
server
{
|CUSTOM|

	listen |IP|:|PORT_80|;
	|MULTI_IP|

	server_name |DOMAIN| www.|DOMAIN| |SERVER_ALIASES|;

	access_log /var/log/nginx/domains/|DOMAIN|.log;
	access_log /var/log/nginx/domains/|DOMAIN|.bytes bytes;
	error_log /var/log/nginx/domains/|DOMAIN|.error.log;
	

	root |DOCROOT|;
  
	index index.php index.html index.htm;
	|*if HAVE_PHP1_FPM="1"|
        # include the "?$args" part so non-default permalinks doesn't break when using query string
		# via http://wiki.nginx.org/Wordpress
        try_files $uri $uri/ /index.php?$args;
		
		# use fastcgi for all php files
		location ~ \.php$
		{
			try_files $uri =404;
			fastcgi_split_path_info ^(.+\.php)(/.+)$;
			include /etc/nginx/fastcgi_params;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			include /etc/nginx/nginx_limits.conf;

			if (-f $request_filename)
			{
				fastcgi_pass unix:/usr/local/php|PHP1_RELEASE|/sockets/|USER|.sock;
			}
		}
	|*endif|
	|*if HAVE_PHP2_FPM="1"|
		# use fastcgi for all php files
		location ~ \.php|PHP2_RELEASE|$
		{
			try_files $uri =404;
			fastcgi_split_path_info ^(.+\.php)(/.+)$;
			include /etc/nginx/fastcgi_params;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			include /etc/nginx/nginx_limits.conf;
			

			if (-f $request_filename)
			{
				fastcgi_pass unix:/usr/local/php|PHP2_RELEASE|/sockets/|USER|.sock;
			}
		}
	|*endif|

|PROTECTED_DIRECTORIES|

	# deny access to apache .htaccess files
	location ~ /\.ht
	{
		deny all;
	}

	include /etc/nginx/webapps.conf;
}
 
Back
Top