实现一台主机下面的多个站点对应于一个nginx服务器的配置过程:
一.配置你的nginx的config文件
1.在nginx的目录下面创建vhosts文件夹
2.文件夹下面创建相关的yy.com.conf oil.com.conf bbk.com.conf配置文件 其中配置文件的内容如下:
我的yy.com.conf的配置
server {
listen 80
#正则匹配 相关的域名yy.cim
server_name ~^yy.com$
location / {
#指定域名对应的路径
root D:/PhpEnvironment/www/yy
#指定默认的访问文件
index index.html index.htm index.php
}
error_page 500 502 503 504 /50x.html
location = /50x.html {
root html
}
location ~ \.php$ {
#指定域名对应的路径
root D:/PhpEnvironment/www/yy/
fastcgi_pass 127.0.0.1:9000
fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
include fastcgi_params
}
}
我的oil.com.conf的配置
server {
listen 80
server_name ~^oil.com$
location / {
root D:/PhpEnvironment/www/oil/public/
index index.html index.htm index.php
}
error_page 500 502 503 504 /50x.html
location = /50x.html {
root html
}
location ~ \.php$ {
root D:/PhpEnvironment/www/oil/public/
fastcgi_pass 127.0.0.1:9000
fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
include fastcgi_params
}
}
我的bbk.com.conf的配置
server {
listen 80
server_name ~^bbk.com$
location / {
root D:/PhpEnvironment/www/bbk/public/
index index.html index.htm index.php
}
error_page 500 502 503 504 /50x.html
location = /50x.html {
root html
}
location ~ \.php$ {
root D:/PhpEnvironment/www/bbk/public/
fastcgi_pass 127.0.0.1:9000
fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
include fastcgi_params
}
}
3. confin/nginx.config的配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
include D:/PhpEnvironment/nginx-1.10.1/vhosts/oil.com.conf;
include D:/PhpEnvironment/nginx-1.10.1/vhosts/yy.com.conf;
include D:/PhpEnvironment/nginx-1.10.1/vhosts/bbk.com.conf;
}
4.检测你的nginx是否配置正确
nginx.exe -t
二.配置你的hosts文件
1.在windows下hosts的文件的路径是
C:\Windows\System32\drivers\etc
我的配置如下:
127.0.0.1 oil.com
127.0.0.1 yy.com
127.0.0.1 bbk.com
2.刷新dns
cmd命令行下:
ipconfig /flushdns
3.重启nginx