D:\nginx\vhost ----虚拟主机conf存放地址三个conf:img.conf,www_test_com.conf,www_test1_com.conf
nginx.conf----
worker_processes 2;
error_log D:/nginx/logs/error.log crit;
pid D:/nginx/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include D:/nginx/conf/mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
keepalive_timeout 60;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
client_body_temp_path D:/nginx/client_body_temp;
proxy_temp_path D:/nginx/proxy_temp;
fastcgi_temp_path D:/nginx/fastcgi_temp;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#设定虚拟主机
include D:/nginx/vhost/www_test_com.conf;
include D:/nginx/vhost/www_test1_com.conf;
include D:/nginx/vhost/img.conf;
}
img.conf,
server {
listen 127.0.0.1:80; #换成你的IP地址
client_max_body_size 100M;
server_name image.anhao.com; #换成你的域名
charset gb2312;
index index.html index.htm index.php;
root C:/Users/sunfx/upload; #你的站点路径
#打开目录浏览,这样当没有找到index文件,就也已浏览目录中的文件
#autoindex on;
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?/$1 last;
}
}
error_page 404 /404.html;
location = /40x.html {
root C:/Users/sunfx/upload; #你的站点路径
charset on;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 3d;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 1d;
access_log off;
}
location ~ \.svn/ {
deny all;
}
location ~ \.php$ {
root C:/Users/sunfx/upload;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME C:/Users/sunfx/upload$fastcgi_script_name;
}
#网站的图片较多,更改较少,将它们在浏览器本地缓存15天
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 15d;
}
#网站会加载很多JS、CSS,将它们在浏览器本地缓存1天
location ~ .*\.(js|css)?$
{
expires 1d;
}
}
www_test_com.conf
server {
listen 127.0.0.1:80; #换成你的IP地址
client_max_body_size 100M;
server_name www.kele.com; #换成你的域名
charset gb2312;
index index.html index.htm index.php;
root C:/Users/sunfx/www/kele; #你的站点路径
#打开目录浏览,这样当没有找到index文件,就也已浏览目录中的文件
#autoindex on;
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?/$1 last;
}
}
error_page 404 /404.html;
location = /40x.html {
root C:/Users/sunfx/www/kele; #你的站点路径
charset on;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 3d;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 1d;
access_log off;
}
location ~ \.svn/ {
deny all;
}
location ~ \.php$ {
root C:/Users/sunfx/www/kele;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
#网站的图片较多,更改较少,将它们在浏览器本地缓存15天
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 15d;
}
#网站会加载很多JS、CSS,将它们在浏览器本地缓存1天
location ~ .*\.(js|css)?$
{
expires 1d;
}
}
www_test1_com.conf
server {
listen 127.0.0.1:80; #换成你的IP地址
client_max_body_size 100M;
server_name www.test1.com; #换成你的域名
charset gb2312;
index index.html index.htm index.php;
root D:/www/example2; #你的站点路径
#打开目录浏览,这样当没有找到index文件,就也已浏览目录中的文件
autoindex on;
if (-d $request_filename) {
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
error_page 404 /404.html;
location = /40x.html {
root D:/www/example2; #你的站点路径
charset on;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root D:/www/example2; #你的站点路径
charset on;
}
#将客户端的请求转交给fastcgi
location ~ .*\.(php|php5|php4|shtml|xhtml|phtml)?$ {
fastcgi_pass 127.0.0.1:9000;
#include D:/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
#网站的图片较多,更改较少,将它们在浏览器本地缓存15天
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 15d;
}
#网站会加载很多JS、CSS,将它们在浏览器本地缓存1天
location ~ .*\.(js|css)?$
{
expires 1d;
}
location /(WEB-INF)/ {
deny all;
}
}