nginx代理websocket服务

./configure --prefix=/usr/local/nginx --with-http_stub_status_module
useradd -s /sbin/nologin -M nginx

nginx.conf

user                    nginx;
worker_processes        2;
worker_rlimit_nofile    262144;
worker_cpu_affinity     00000001 00000010;

error_log  /usr/local/nginx/logs/error.log;

pid        /var/run/nginx.pid;

events {
    use epoll;
    multi_accept on;
    worker_connections  10000;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    access_log /usr/local/nginx/logs/access.log;
    server_names_hash_bucket_size   128;
    client_header_buffer_size       128k;
    large_client_header_buffers     4 128k;

    underscores_in_headers    on;    

    proxy_connect_timeout 5;
    proxy_read_timeout 60;
    proxy_send_timeout 5;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
    proxy_temp_path /usr/local/nginx/nginx_cache/temp_dir;
    proxy_cache_path /usr/local/nginx/nginx_cache/cache/one  levels=1:2   keys_zone=one:1024m inactive=1d max_size=10g;
    proxy_cache_key  $host$uri$is_args$args;

    sendfile        on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   60;
    send_timeout        30;
    server_tokens       off;    
    server {
        listen       80;        
        location /NginxStatus { 
            access_log  off; 
            stub_status on; 
            allow   127.0.0.1; 
            deny    all; 
        }
        location / { rewrite ^(.*)$  http://www.letv.com redirect;}                       
    }

    include /usr/local/nginx/conf.d/*.conf;
}

ups-wawaji-api.conf

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }   

    upstream ww.websocket {     
        server 10.185.29.1:***;
    }

    server {
        listen       80;
        server_name  ww.duohappy.cn;        

        location /catchToy {
            proxy_pass   http://ww.websocket;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
        }       

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }  

你可能感兴趣的:(【系统运维】)