nginx node pm2

7319 단어
ubuntu 에서 의 조작
$sudo /etc/init.d/nginx start //  
$sudo /etc/init.d/nginx stop //  
$sudo /etc/init.d/nginx restart //  

//    /etc/nginx/nginx.conf
#/usr/local/nginx/conf/nginx.conf

설치 의존
1. 모듈 의존성 gzip 모듈 은 zlib 라 이브 러 리 rewrite 모듈 이 필요 합 니 다. pcre 라 이브 러 리 ssl 기능 이 필요 합 니 다. openssl 라 이브 러 리 가 미리 컴 파일 된 설치 패키지 가 필요 합 니 다.
sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev 

명령 설치
#  nginx    download  
wget  http://nginx.org/download/nginx-1.6.2.tar.gz
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --user=wwwuser --group=wwwgroup --prefix=/usr/local/nginx/ --with-http_ssl_module
#            ,--user     --group     --prefix       --with-http_ssl_module  https  ,      
make & make install
#       /usr/local/nginx   whereis nginx   #        
#  
 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 
#      
 /usr/local/nginx/sbin/nginx -s reload 
#   
/usr/local/nginx/sbin/nginx -s stop 
#         
/usr/local/nginx/sbin/nginx -t
#             
      curl
lsof -i:80 
#     curl 127.0.0.1

nginx 역방향 에이전트 와 부하 균형
최 악의 배치
#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  6666;
}
http {
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    gzip  on;
    upstream myNodejs{
        ip_hash;
        server 127.0.0.1:3001 weight=3;
    }
    upstream myPython{
        ip_hash;
        server 127.0.0.1:8888 weight=3;
    }
    server {
        listen       80;
        listen       443;
        server_name  node.boqiao919.com;
    ssl on;
        ssl_certificate   cert/213991280040065.pem;
        ssl_certificate_key  cert/213991280040065.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
        location / {
            proxy_pass http://myNodejs;
        }
    }
    server {
        listen       80;
        listen       443;
        server_name  python.boqiao919.com;
    ssl on;
        ssl_certificate   cert/213991280040065.pem;
        ssl_certificate_key  cert/213991280040065.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        location / {
            proxy_pass http://myPython;
        }
    }
   server {
        listen       80;
        listen       443;
        server_name  boqiao919.com;
        ssl on;
    ssl_certificate   cert/213991280040065.pem;
    ssl_certificate_key  cert/213991280040065.key;
        ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
        {
        root /home/liyang/nginxStatic;
            expires 15d;
        }
    }
}

eg:
#user  nobody;
worker_processes  1;
events {
    worker_connections  6666;
}
http {
    gzip  on;
    upstream myNodejs{
        ip_hash;
        server 127.0.0.1:3001 weight=3;
    }
    upstream myPython{
        ip_hash;
        server 127.0.0.1:8888 weight=3;
    }
    server {
        listen       80;
        server_name  node.boqiao919.com;
        location / {
            proxy_pass http://myNodejs;
        }
    }
    server {
        listen       80;
        server_name  node.boqiao919.com;
        location / {
            proxy_pass http://myPython;
        }
    }
}

eg:
#    (     root,        root       )
#user  nobody;
#       ,     cpu     cpu   2 
worker_processes  1;
#          (notice info      )
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#  pid    (pid           )
#pid        logs/nginx.pid;
#       
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #      
    #gzip  on;
    #      
    #gzip_min_lenth 1k;
    #             
    #gzip_buffers 4 16k;
    #  http     
    #gzip_http_version 1.1;
    #         gzip,      
    #gzip_vary on;
    #       
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
        #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;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

좋은 웹페이지 즐겨찾기