zoukankan      html  css  js  c++  java
  • linux下nginx的安装

    以Red Hat Enterprise Linux 5为例进行讲解。

     

    相关系列:

    linux下jdk的安装

    linux下ant的安装

    linux下redis的安装

    linux下svn的安装

    linux下nginx的安装

    linux下graphviz的安装

    linux下doxygen的安装

     

     

     

    安装nginx版本为0.8.36

    一。下载nginx

    下载地址:http://www.nginx.org/

    选择nginx-0.8.36

    将该下载包拷贝到/usr/local/下(随意了,找个地方就好)

     

    二。安装

    cd /usr/local/

    tar zxvf nginx-0.8.36.tar.gz

    cd nginx-0.8.36

     

    按照一些网络资料的介绍,执行如下命令即可完成安装

    ./configure

    make

    make install

     

    但在实际安装过程中会,执行./configure时,根据系统的配置不同会有不同的错误提示,这里不罗嗦了,安装nginx需要安装openssl和 pcre,

    openssl在linux下svn的安装中有过介绍,这里不再赘述,下面只介绍一下pcre的安装,如下:

    下载pcre:http://sourceforge.net/projects/pcre/files/ ,选择pcre-8.02.tar.gz,拷贝到/usr/local/下

    tar -zxvf pcre-8.02.tar.gz

    cd pcre-8.02

    ./configure --prefix=/usr/local/pcre

    make

    make install

     

    ok,pcre安装完成

     

    接着我们安装nginx,

    cd /usr/local/nginx-0.8.36

     

    ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.02 --with-http_ssl_module --with-openssl=/usr/local/openssl-0.9.8o

     

    make

     

    make install

     

    ok,nginx安装完成。

     

    三。配置

     修改 /usr/local/nginx/conf/nginx.conf 来满足自己的需求,下面给一个负载的小实例

    Java代码  收藏代码
    1. user  nginx;#确保存在这个用户  
    2. worker_processes  2 
    3.   
    4. error_log  /var/log/nginx/error.log  info;#确保路径存在  
    5.   
    6. pid        logs/nginx.pid;  
    7.   
    8.   
    9. events  
    10.     worker_connections  1024 
    11.     multi_accept on;  
    12.     use epoll;  
    13.  
    14.   
    15.   
    16. http  
    17.     include       mime.types;  
    18.     default_type  application/octet-stream;  
    19.   
    20.     log_format  main  '$remote_addr $remote_user [$time_local] $request '  
    21.                       '"$status" $body_bytes_sent "$http_referer" '  
    22.                       '"$http_user_agent" "$http_x_forwarded_for"' 
    23.   
    24.     access_log  /var/log/nginx/access.log  main;  
    25.   
    26.     sendfile        on;  
    27.     #tcp_nopush     on;  
    28.   
    29.     keepalive_timeout  30 
    30.   
    31.     #gzip  on;  
    32.   
    33.     server_names_hash_bucket_size 128 
    34.     upstream tomcats  
    35.          server 192.168.0.104:8888 weight=3 
    36.          server 192.168.2.94:8888 weight=2  
    37.          ip_hash;  
    38.      
    39.      
    40.   
    41.     server  
    42.         listen       80 
    43.   
    44.         charset gb2312;  
    45.         add_header test private 
    46.   
    47.         location  
    48.             root   /usr/local/test/boss/test;  
    49.             index  index.html index.htm index.jsp;  
    50.   
    51.             proxy_pass http://tomcats;  
    52.             proxy_redirect off;  
    53.             proxy_set_header Host $host;  
    54.             proxy_set_header X-Real-IP $remote_addr;  
    55.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    56.             client_max_body_size 50m;  
    57.             client_body_buffer_size 256k;  
    58.             proxy_connect_timeout 10 
    59.             proxy_send_timeout 15 
    60.             proxy_read_timeout 15 
    61.             proxy_buffer_size 4k;  
    62.             proxy_buffers 4 32k;  
    63.             proxy_busy_buffers_size 64k;  
    64.             proxy_temp_file_write_size 64k;  
    65.          
    66.   
    67.         error_page   500 502 503 504  /50x.html;  
    68.         location /50x.html  
    69.             root   html;  
    70.          
    71.   
    72.    
    73.   
    74.  

     注意,这里nginx监听80端口,所以要在iptables里打开80端口。

    启动nqinx:

    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

     

    接着访问这台机器的80的端口,如果请求成功,则说明配置成功。

     

    为了操作方便,可以自己写一个nginx命令脚本,放到/etc/init.d下,并赋予其执行权限即可,详见附件,执行方法如下:

    启动:service nginx start

    停止:service nginx stop

    重启:service nginx reconfigure

    查看状态:service nginx status

     

    nginx升级或重新编译时平滑启动的方法:

    1.执行编译nginx,并覆盖原来的路径

    2.kill -USR2 旧nginx主进程号:此时会在不关闭老进程的情况下启动一个新的nginx进程

    3.kill -WINCH 旧nginx主进程号:查看老的工作进程是否还在使用,不使用时就关闭,如下

    4.kill -QUIT 旧nginx主进程号:关闭旧nginx主进程

    ----夫英雄者,胸怀大志,腹有良谋,有包藏宇宙之机,吞吐天地之志者也。
  • 相关阅读:
    Laravel artisan 命令工具
    WIN10安装office2003/7失败 WIN10安装office2003权限不足解决
    64windows位安装tensorflow
    Swing图层的应用——实现tooltip显示
    spring加载xml的六种方式
    ubuntu 添加右键打开方式,无法添加程序打开方式
    3.3.4 配置Tomcat的<Context>元素 (转)
    百度tn劫持解决办法
    java代理模式
    js作用域
  • 原文地址:https://www.cnblogs.com/eagleking0318/p/6521051.html
Copyright © 2011-2022 走看看