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

来源:互联网 发布:h5斗牛源码网站 编辑:程序博客网 时间:2024/04/26 12:11

          虚拟主机即使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 ipv6root /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.htmltry_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/