linux centos nginx 虚礼主机 反向代理 配置

来源:互联网 发布:flash编程视频教程 编辑:程序博客网 时间:2024/05/16 05:50

nginx.conf文件:


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
user www www; 
worker_processes 4;
error_log /usr/local/nginx/logs/nginx_error.log crit; 
pid /usr/local/nginx/nginx.pid; 
worker_rlimit_nofile 51200; 
  
events 
    use epoll; 
    worker_connections 51200;
  
http 
    log_format  main '$remote_addr - $remote_user [$time_local] $request'
    'upstream_response_time $upstream_response_time' 'msec $msec request_time $request_time';
 
    include mime.types; 
    default_type application/octet-stream; 
 
    server_names_hash_bucket_size 128; 
    client_header_buffer_size 32k; 
    large_client_header_buffers 4 32k; 
    client_max_body_size 30m; 
 
    sendfile on; 
    #tcp_nopush on; 
    #server_tokens off;
    keepalive_timeout 30; 
 
    tcp_nodelay on; 
 
    #注:proxy_temp_path和proxy_cache_path指定的路径必须在同一分区 
    proxy_temp_path /data/proxy_temp_dir; 
    #设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天清理一次缓存,硬盘缓存空间大小为30GB。 
    proxy_cache_path /data/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;
    include vhost/*.conf;
}
虚礼主机配置文件:



?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
server
{
    #这个端口,表示代理服务器为example.com域名开设的端口
    #这个example.com就是后端服务器的域名
    listen 80;
    server_name example.com;
 
    access_log  /logs/example.com.log  main;
    location / {
        proxy_pass http://后端服务器的ip:port;
        proxy_set_header Host $host;
        #这里再header里面设置代理服务器的ip
        proxy_set_header X-Forwarded-For $remote_addr;
    }
    #设置缓存的图片等资源的时间,缓存名cache_one在nginx.conf里面有定义
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
    {
        proxy_cache cache_one;
        proxy_cache_valid 200 304 12h;
        proxy_cache_valid 301 302 1m;
        proxy_cache_valid any 1m;
        proxy_cache_key $host$uri$is_args$args;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://后端服务器的ip:port;
    }
    #这个在虚礼主机里面有说明,是nginx的一个bug修复
    if($request_uri ~ " ") {
        return444;
    }
}
0 0
原创粉丝点击