Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

35.10. 单域名虚拟主机

			
# cat /etc/nginx/conf.d/images.conf
server {
	listen 80;
	server_name images.example.com;
	
	#charset koi8-r;
	access_log /var/log/nginx/images.access.log main;
	
	location / {
		root /www/images;
		index index.html index.htm;
	}
	
	#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/html;
	}
	
	# proxy the PHP scripts to Apache listening on 127.0.0.1:80
	#
	#location ~ \.php$ {
	# proxy_pass http://127.0.0.1;
	#}
	
	# pass the
	PHP scripts to FastCGI server listening on 127.0.0.1:9000
	#
	#location ~ \.php$ {
	# root html;
	# fastcgi_pass 127.0.0.1:9000;
	# fastcgi_index index.php;
	# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
	# include fastcgi_params;
	#}
	
	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	# deny all;
	#}
}
			
	

绑定多个域名

			
	server_name images.example.com img1.example.com img2.example.com;
			
	

使用通配符匹配

			
	server_name *.example.com
	server_name www.*;
			
	

正则匹配

			
	server_name ~^(.+)\.example\.com$;
	server_name ~^(www\.)?(.+)$;