nginx搭建虚拟主机的配置文件方法

          虚拟主机即使server所以,nginx中用一个server{。。。}来表示一个虚拟主机,n个虚拟主机所以就用n个server{。。。}

          server的基本配置文件如下

          

server {
	listen   7888; ## listen for ipv4; this line is default and implied这个虚拟主机用的端口
	#listen   [::]:80 default ipv6only=on; ## listen for ipv6

	root /usr/share/nginx/www;#虚拟主机对应的站点资源目录
	index index.html index.htm;#虚拟主机默认的入口文件

	# Make site accessible from http://localhost/
	server_name localhost;#虚拟主机绑定的域名

	location / {#请求根目录,默认的入口
		# First attempt to serve request as file, then
		# as directory, then fall back to index.html
		try_files $uri $uri/ /index.html;
	}

	location /doc {#虚拟目录

		root /usr/share;
		autoindex on;
		allow 127.0.0.1;
		deny all;
	}

	location /images {
		root /usr/share;
		autoindex off;
	}

	#error_page 404 /404.html;#404错误页面

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

	# 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$ {
	#	fastcgi_pass 127.0.0.1:9000;
	#	fastcgi_index index.php;
	#	include fastcgi_params;
	#}

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

搭建一个简单的虚拟主机很简单,但是如果加上一些修改,例如负载均衡,代理,重定向,ssl,.htaccess等等可能需要好好学习一下了。官方文档,第一手的资料,还等什么


http://nginx.org/en/docs/         

你可能感兴趣的:(apache,nginx,server,负载均衡,redirect,.htaccess)