본문 바로가기
OS & Infra/Service Infra

[NginX] Dynamic Virtual Host

by Dev. Jkun 2021. 10. 19.
반응형

일단 아직 실행해보지는 않았지만 Keep 해둔다. 링크

다음은 Nginx 설정사항 이다.

server {
	index index.php;
	set $basepath "/var/www";

	set $domain $host;

	# check one name domain for simple application
	if ($domain ~ "^(.[^.]*)\.dev$") {
		set $domain $1;
		set $rootpath "${domain}";
		set $servername "${domain}.dev";
	}

	# check multi name domain to multi application
	if ($domain ~ "^(.*)\.(.[^.]*)\.dev$") {
		set $subdomain $1;
		set $domain $2;
		set $rootpath "${domain}/${subdomain}/www/";
		set $servername "${subdomain}.${domain}.dev";
	}

	server_name $servername;

	access_log "/var/log/nginx/server.${servername}.access.log";
	error_log "/var/log/nginx/server.dev.error.log";

	root $basepath/$rootpath;

	# check file exist and send request sting to index.php 
	location / {
		try_files $uri $uri/ /index.php?$args;
	}

	# allow php only in root index.php
	#location ~ "^/index\.php$" {
	# allow execute all php files
	location ~ \.php$ {
		try_files $uri =404;
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
	
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		include fastcgi_params;
	}

	# configure phpmyadmin path
	location /phpmyadmin {
		root /usr/share/;
		index index.php;
		location ~ ^/phpmyadmin/(.+\.php)$ {
			try_files $uri =404;
			root /usr/share/;
			fastcgi_pass unix:/var/run/php5-fpm.sock;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $request_filename;
			include 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;
	}

	# disallow access to apache configs
	location ~ /\.ht {
		deny all;
	}

	# disallow access to git configs path
	location ~ /\.git {
		deny all;
	}

	# disallow access to yii code path
	location ~ /(protected|themes/classic/views)/ {
		deny all;
	}
}
반응형

댓글