标签:否则 pid div usr png roo cat nginx 包含
http {
server {
listen 80;
server_name www.domain1.com;
access_log logs/domain1.access.log main;
location / {
index index.html;
root /web/www/domain1.com/htdocs;
}
}
server {
listen 80;
server_name www.domain2.com;
access_log logs/domain2.access.log main;
location / {
index index.html;
root /web/www/domain2.com/htdocs;
}
}
include /opt/nginx/conf/vhosts/www.domain2.com.conf;
}
这里用到了include指令,其中/opt/nginx/conf/vhosts/www.domain2.com.conf的内容为:
server {
listen 80;
server_name www.domain3.com;
access_log logs/domain3.access.log main;
location / {
index index.html;
root /web/www/domain3.com/htdocs;
}
}
http
{
upstream myserver {
server 192.168.12.181:80 weight=3 max_fails=3 fail_timeout=20s;
server 192.168.12.182:80 weight=1 max_fails=3 fail_timeout=20s;
server 192.168.12.183:80 weight=4 max_fails=3 fail_timeout=20s;
}
server
{
listen 80;
server_name www.domain.com 192.168.12.189;
index index.htm index.html;
root /ixdba/web/wwwroot;
location / {
proxy_pass http://myserver;
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
include /opt/nginx/conf/proxy.conf;
}
}
}
在上面这个配置实例中,首先定义了一个负载均衡组myserver,然后在location部分通过“proxy_pass http://myserver”实现负载调度功能,其中proxy_pass指令用来指定代理的后端服务器地址和端口,地址可以是主机名或者IP地址,也可以是通过upstream指令设定的负载均衡组名称。
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
location ~* \.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar)$ {
valid_referers none blocked *.ixdba1.net ixdba1.net;
if ($invalid_referer) {
rewrite ^/ http://www.ixdba.net/img/error.gif;
#return 403;
}
}
location /images {
root /opt/nginx/html;
valid_referers none blocked *.ixdba1.net ixdba1.net;
if ($invalid_referer) {
return 403;
}
}
#/bin/bash savepath_log=‘/home/nginx/logs‘ nglogs=‘/opt/nginx/logs‘ mkdir -p $savepath_log/$(date +%Y)/$(date +%m) mv $nglogs/access.log $savepath_log/$(date +%Y)/$(date +%m)/access.$(date +%Y%m%d).log mv $nglogs/error.log $savepath_log/$(date +%Y)/$(date +%m)/error.$(date +%Y%m%d).log kill -USR1 `cat /opt/nginx/logs/nginx.pid`
标签:否则 pid div usr png roo cat nginx 包含
原文地址:http://www.cnblogs.com/skyflask/p/7512664.html