My PHP programming companions with nginx and hhvm for the best configuration. sometime we need some many location or doc root or maybe some many virtual server.

nginx consists of modules which are controlled by directives specified in the configuration file. Directives are divided into simple directives and block directives. A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;). A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces ({ and }). If a block directive can have other directives inside braces, it is called a context (examples: events, http, server, and location).

Directives placed in the configuration file outside of any contexts are considered to be in the main context. The events and http directives reside in the main context, server in http, and location in server.

The rest of a line after the # sign is considered a comment.

This is my configuration with debian using nginx and hhvm and yii2 which no www redirect :

in your /etc/sites-available/default :

 

server {
	listen   80; ## listen for ipv4; this line is default and implied
        server_name www.sintret.com;
	return  301 http://sintret.com$request_uri;
}
server {
  	listen   80; ## listen for ipv4; this line is default and implied
        server_name sintret.com;
	charset      utf-8;
   	client_max_body_size  200M;
	#listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

	#access_log    /usr/share/nginx/www/sintret.log main buffer=50k;	
	error_log    /usr/share/nginx/www/sintret.com.error.log notice;
	root /usr/share/nginx/www;
	index index.php index.html index.htm;

	# Make site accessible from http://localhost/
	
	include hhvm.conf;

	location / {
		root  /usr/share/nginx/www/frontend/web;
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ /index.php?$args;
		try_files  $uri /frontend/web/index.php?$query_string;
                autoindex off;
		#try_files $uri $uri/ /index.html;
 		# avoiding processing of calls to non-existing static files by Yii
        	location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
            	access_log  off;
            	expires  30d;
            	try_files  $uri =404;
        	}
	}
        location /recording {
        	alias  /usr/share/nginx/www/recording;
                try_files  $uri /recording/index.php?$args;
    	}
       
        location /whatsapp {
        	alias  /usr/share/nginx/www/whatsapp;
    	}
        location /download {
        	alias  /usr/share/nginx/www/download;
    	}

        location /adiadrian {
            alias  /usr/share/nginx/www/adiadrian/web;
            rewrite ^/adiadrian/(.*)$ /adiadrian/web/index.php?$args;
        } 
        # the images need a seperate entry as we dont want to concatenate that with index.php      
        location ~ ^/adiadrian/(.+\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|eot|woff|ttf|svg|xls|xlsx))$ {
        	access_log  off;
        	expires  360d;

        	rewrite  ^/adiadrian/(.+)$ /adiadrian/web/$1 break;
        	try_files  $uri =404;
    	}
        
	location /webadmin {
        	alias  /usr/share/nginx/www/backend/web;

        	rewrite  ^(/webadmin)/$ $1 permanent;
        	try_files  $uri /backend/web/index.php?$args;
    	}
	# avoiding processing of calls to non-existing static files by Yii
    	location ~ ^/webadmin/(.+\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|eot|woff|ttf|svg|xls|xlsx))$ {
        	access_log  off;
        	expires  360d;

        	rewrite  ^/webadmin/(.+)$ /backend/web/$1 break;
        	try_files  $uri =404;
    	}

	location /doc/ {
		alias /usr/share/doc/;
		autoindex on;
		allow 127.0.0.1;
		allow ::1;
		deny all;
	}

	# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
	#location /RequestDenied {
	#	proxy_pass http://127.0.0.1:8080;    
	#}

	#error_page 404 /404.html;

	# redirect server error pages to the static page /50x.html
	#
	#error_page 500 502 503 504 /50x.html;
	#location = /50x.html {
	#	root /usr/share/nginx/www;
	#}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	#
	#location ~ \.php$ {
	#	fastcgi_split_path_info ^(.+\.php)(/.+)$;
	#	# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
	#
	#	# With php5-cgi alone:
	#	fastcgi_pass 127.0.0.1:9000;
	#	# With php5-fpm:
	#	try_files $uri =404;
	#	fastcgi_pass unix:/var/run/php5-fpm.sock;
	#	fastcgi_index index.php;
	#	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	#	include fastcgi_params;
	#}
 	location = /requirements.php {
        	deny all;
    	}

    location ~ \.(ht|svn|git) {
        deny all;
    }

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	#	deny all;
	#}
}

 

 

Leave a Comment:



digital_ocean