六、Nginx虚拟主机配置
建立基于域名的虚拟主机:
(1)建立基于域名的虚拟主机配置文件(以abc.com为例):
(2)更改虚拟主机配置文件:
更改配置如下(更改部分即可):
server {
listen 80; #侦听端口
server_name abc.com; #虚拟机主机名(这里填入域名绑定)
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
root /mnt/www/abc.com; #指定WEB根目录
location / {
index index.php 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;
#}
}
(以上是基于域名的Nginx虚拟主机基本配置,更详细的配置请见LNMP配置)
配置完成,重新加载服务:
(本文由kayvan编辑发表,内容主要收集于互联网,转载请注明出处:http://www.cnblogs.com/kayvan)