#user nobody; worker_processes 1; error_log logs/error.log; error_log logs/error.log notice; error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } #upstream servers { #upstream的负载均衡,weight是权重,可以根据机器配置定义权重。weigth参数表示权值,权值越高被分配到的几率越大。 #server 192.168.0.237:80 weight=3; #server 192.168.0.14:80 weight=3; #} #location / { #root www/example1.com; # proxy_pass http://servers; #proxy_set_header Host $host; #proxy_set_header X-Real-IP $remote_addr; #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #index index.php index.html index.htm; #} http { #这个是限制连接的存储区 #这个是限制请求的存储区 include mime.types; default_type application/octet-stream; sendfile on; server { listen 80; server_name _; server_name_in_redirect off; location / { root www; index index.html; } } #设置上传文件的大小 client_max_body_size 2m; #虚拟主机1 server { listen 80; server_name example2.com www. example2.com; location / { root www/example2.com; index index.php index.html index.htm; if (!-e $request_filename) { rewrite ^/(.*) /index.php?/$1 last; rewrite "(.*?)(\.html)$" $1 last; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root www; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ .php$ { fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME www/example2.com/$fastcgi_script_name; include fastcgi_params; } location ~ /.ht { deny all; } } #虚拟主机2 server { listen 80; server_name example1.com www. example1.com; #缓存相应的文件(静态文件) location ~ .*\.(gif|jpg|png|css|js|flv|ico|swf)(.*) { # proxy_pass http://example1.com; #如果没有缓存则通过proxy_pass转向请求 proxy_redirect off; proxy_set_header Host $host; proxy_cache_valid 200 302 1h; #对不同的HTTP状态码设置不同的缓存时间,h小时,d天数 proxy_cache_valid 301 1d; proxy_cache_valid any 1m; expires 30m; } location / { #压缩配置# gzip on; #打开gzip压缩功能 gzip_min_length 1k; #压缩阈值 gzip_buffers 4 16k; #buffer 不用修改 gzip_comp_level 2; #压缩级别:1-10,数字越大压缩的越好,时间也越长 gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 压缩文件类型 gzip_vary off; #跟Squid等缓存服务有关,on的话会在Header里增加 "Vary: Accept-Encoding" gzip_disable "MSIE [1-6]\."; #IE1-6版本不支持gzip压缩 root www/example1.com; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root www; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ .php$ { fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME www/example1.com/$fastcgi_script_name; include fastcgi_params; } location ~ /.ht { deny all; } } #虚拟主机3 server { listen 80; server_name localhost; location / { root html; index index.php index.html; if (!-e $request_filename) { rewrite ^/(.*) /index.php?/$1 last; rewrite "(.*?)(\.html)$" $1 last; } } #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 html; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; client_max_body_size 4112M; fastcgi_param SCRIPT_FILENAME html$fastcgi_script_name; include fastcgi_params; } client_max_body_size 2m; } }
nginx虚拟机配置
猜你喜欢
转载自blog.csdn.net/qq_26959879/article/details/80064540
今日推荐
周排行