Nginx+Resin

 

#user  nobody;
worker_processes  2; #设置Nginx启动2个线程

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  2048;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #设置log的格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #设置log保存的位置
    access_log  /usr/local/boss_log/nginx_log/access.log  main;

    #sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    #keepalive_timeout  65;

    #gzip  on;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 1 128k;
    client_max_body_size 8m;

    # resolve nginx 502/504 error
    sendfile on;
    send_timeout 120;
    tcp_nopush     on;

    keepalive_timeout 120; #60

    tcp_nodelay on;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 8 128k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;

    # resolve nginx 502/504 error end  

    # 将请求分发到5个Resin web 服务,其对应的IP:端口为 127.0.0.1:808[0~4]
    upstream 192.168.60.119{
    ip_hash;    #设置请求的IP来分发web 服务,来保证Session 正常工作
    server 127.0.0.1:8080 max_fails=0; #max_fails=0 发现错误立即切换
    server 127.0.0.1:8081 max_fails=0;
    server 127.0.0.1:8082 max_fails=0;
    server 127.0.0.1:8083 max_fails=0;
    server 127.0.0.1:8084 max_fails=0;
    }

    server {
        client_max_body_size 30M; 
        listen       80;
        server_name  127.0.0.1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            index  index.jsp;
            proxy_pass  http://192.168.61.111;
	    proxy_set_header X_REAL_IP $remote_addr;
	    proxy_set_header X_HOST $host;
	    proxy_set_header X_FORWARDED_FOR $proxy_add_x_forwarded_for;
        }

        location ~ ^/NginxStatus/* {
            stub_status on;
            access_log off;
        }

        #设置图片等直接用nginx的服务,不转发到 Resin web
        location ~ .*/.(gif|jpg|jpeg|png|bmp|swf)$ {
	    root /mnt/webFiles/bossSite_Common;
            expires 1d;
        }

        location ~ .*/.(gif|jpg|jpeg|png|bmp|swf)$ {
            root /usr/local/boss_workspace/boss;
           expires 1d;
        }

        #设置js,css直接用nginx的服务,不转发到 Resin web
        #location ~ .*/.(js|css)?$ {
	#    root /usr/local/boss_workspace/boss;
        #    expires 1h;
        #}

}
 

 

 

 

 

 

 

 

 

 

<!-- The http port -->
    <http server-id="web-a" host="*" port="8080"/>
    <http server-id="web-b" host="*" port="8081"/>
    <http server-id="web-c" host="*" port="8082"/>
    <http server-id="web-d" host="*" port="8083"/>
    <http server-id="web-e" host="*" port="8084"/>

    <cluster>
      <srun server-id="web-a" host="127.0.0.1" port="6802"/>
      <srun server-id="web-b" host="127.0.0.1" port="6803"/>
      <srun server-id="web-c" host="127.0.0.1" port="6804"/>
      <srun server-id="web-d" host="127.0.0.1" port="6805"/>
      <srun server-id="web-e" host="127.0.0.1" port="6806"/>
    </cluster>
 
./bin/httpd.sh -conf ./conf/resin_nginx.conf  -server web-[a-e] -Xmn256m

 启动nginx的命令

cd /usr/local/nginx ./nginx

停止nginx的命令 ./nginx -s stop

nginx 没有自动截取log的方法,用如下命令来替代。

1 建立脚本 /usr/local/nginx/sbin/cut_nginx_log.sh

#!/bin/bash
# This script run at 00:00

# The Nginx logs path
logs_path="/usr/local/boss_log/nginx_log/"

mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`

2 设置crontab,每天凌晨00:00切割nginx访问日志

crontab -e

输入以下内容

00 00 * * * /bin/bash  /usr/local/nginx/sbin/cut_nginx_log.sh

主进程可以处理以下的信号:

 

TERM, INT 快速关闭
QUIT 从容关闭
HUP 重载配置 用新的配置开始新的工作进程 从容关闭旧的工作进程
USR1 重新打开日志文件
USR2 平滑升级可执行程序。
WINCH 从容关闭工作进程

nginx+resin 工作,resin作如下设置

1 建立resin_nginx.conf, 放在 {RESIN_HOME}/conf下,除了以下内容,其余配置和原来resin.conf的内容相同。

    <!-- The http port -->
    <http server-id="web-a" host="*" port="8080"/>
    <http server-id="web-b" host="*" port="8081"/>
    <http server-id="web-c" host="*" port="8082"/>
    <http server-id="web-d" host="*" port="8083"/>
    <http server-id="web-e" host="*" port="8084"/>

    <cluster>
      <srun server-id="web-a" host="127.0.0.1" port="6802"/>
      <srun server-id="web-b" host="127.0.0.1" port="6803"/>
      <srun server-id="web-c" host="127.0.0.1" port="6804"/>
      <srun server-id="web-d" host="127.0.0.1" port="6805"/>
      <srun server-id="web-e" host="127.0.0.1" port="6806"/>
    </cluster>

2 建立 resin-nginx-[a-e].sh, 放在 {RESIN_HOME},内容如下

./bin/httpd.sh -conf ./conf/resin_nginx.conf  -server web-[a-e] -Xmn256m

3 依次执行resin-nginx-a.sh,resin-nginx-b.sh...resin-nginx-e.sh,启动resin web服务

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(nginx)