解读nginx之虚拟主机
2011-01-10 11:35
801 查看
基于域名的虚拟主机
http {
index index.html; #默认文件顺序
server {
server_name www.domain1.com; #服务器名
access_log logs/domain1.access.log main; #日志记录
root /var/www/domain1.com/htdocs; #网站目录
}
server {
server_name www.domain2.com;
access_log logs/domain2.access.log main;
root /var/www/domain2.com/htdocs;
}
}
--------
基于ip的虚拟主机
http {
server{
listen
192.168.1.201:80; #监听的IP地址和端口
server_name
192.168.1.201; #主机名
access_log log/server201.access.log
combined; #访问日志的位置
location /
{
index index.html
index.htm #默认文件
root html1 #默认目录位置
}
}
#增加第二个虚拟主机
server{
#监听的IP地址和端口
listen
192.168.1.201:80;
#主机名
server_name
192.168.1.201;
#访问日志的位置
access_log log/server201.access.log
combined;
location /
{
#默认文件
index index.html
index.htm
#默认目录位置
root
html1
}
}
#增加第三个虚拟主机
server{
#监听IP地址和端口
listen
192.168.1.202:80;
#主机名
server_name
192.168.1.201;
#访问日志的位置
access_log log/server202.access.log
combined;
location /
{
#默认文件
index index.html
index.htm
#默认目录位置
root html2
}
}
}
==============================
另附指定所有的二级域名
server {
# Replace this port with the right one for your requirements
listen 80 [default|default_server]; #could also be 1.2.3.4:80 监听端口
# Multiple hostnames separated by spaces. Replace these as well.
server_name star.yourdomain.com *.yourdomain.com;
# Alternately: _
root /PATH/TO/WEBROOT/$host;
error_page 404 errors/404.html; #错误页
access_log logs/star.yourdomain.com.access.log;
index index.php index.html index.htm;
# serve static files directly
location ~* /.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~ /.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
# By all means use a different server for the fcgi processes if you need to
fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE;
}
location ~ //.ht {
deny all;
}
}
http {
index index.html; #默认文件顺序
server {
server_name www.domain1.com; #服务器名
access_log logs/domain1.access.log main; #日志记录
root /var/www/domain1.com/htdocs; #网站目录
}
server {
server_name www.domain2.com;
access_log logs/domain2.access.log main;
root /var/www/domain2.com/htdocs;
}
}
--------
基于ip的虚拟主机
http {
server{
listen
192.168.1.201:80; #监听的IP地址和端口
server_name
192.168.1.201; #主机名
access_log log/server201.access.log
combined; #访问日志的位置
location /
{
index index.html
index.htm #默认文件
root html1 #默认目录位置
}
}
#增加第二个虚拟主机
server{
#监听的IP地址和端口
listen
192.168.1.201:80;
#主机名
server_name
192.168.1.201;
#访问日志的位置
access_log log/server201.access.log
combined;
location /
{
#默认文件
index index.html
index.htm
#默认目录位置
root
html1
}
}
#增加第三个虚拟主机
server{
#监听IP地址和端口
listen
192.168.1.202:80;
#主机名
server_name
192.168.1.201;
#访问日志的位置
access_log log/server202.access.log
combined;
location /
{
#默认文件
index index.html
index.htm
#默认目录位置
root html2
}
}
}
==============================
另附指定所有的二级域名
server {
# Replace this port with the right one for your requirements
listen 80 [default|default_server]; #could also be 1.2.3.4:80 监听端口
# Multiple hostnames separated by spaces. Replace these as well.
server_name star.yourdomain.com *.yourdomain.com;
# Alternately: _
root /PATH/TO/WEBROOT/$host;
error_page 404 errors/404.html; #错误页
access_log logs/star.yourdomain.com.access.log;
index index.php index.html index.htm;
# serve static files directly
location ~* /.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~ /.php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
# By all means use a different server for the fcgi processes if you need to
fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE;
}
location ~ //.ht {
deny all;
}
}
相关文章推荐
- Nginx配置解读,虚拟主机,https配置,反向代理,https重定向
- nginx/windows: nginx多虚拟主机配置
- Nginx反向代理多虚拟主机及记录真实客户IP
- Nginx实战(一) 虚拟主机
- nginx虚拟主机设置
- NGINX虚拟主机管理
- window下phpstudy的nginx配置虚拟主机和伪静态
- nginx部署基于ip的虚拟主机
- Nginx多站点虚拟主机实现单独启动停止php-fpm、单独控制权限设置
- 通过ngx-lua来统计Nginx上的虚拟主机性能数据
- Nginx 安装笔记(含PHP支持、虚拟主机、反向代理负载均衡)
- 在Nginx中部署基于IP的虚拟主机
- nginx配置虚拟主机相关教程
- 商城项目实战38:系统架构梳理及Nginx的三种虚拟主机方式
- centos下为laravel框架配置nginx服务器虚拟主机
- Nginx安装、默认虚拟主机、用户认证、nginx中PHP解析
- 如何在Ubuntu 14.04 LTS之上设置Nginx Server Blocks(即虚拟主机)
- 在Nginx中部署基于IP的虚拟主机
- Nginx 虚拟目录和虚拟主机的配置
- 以wordpress为例在nginx上配置虚拟主机