---
title: "nginx安装配置"
author: "awfrun"
date: "2012-07-19T18:48:52Z"
tags: []
categories: ["开源软件"]
slug: "nginx"
draft: false
lastmod: "2012-07-19T18:48:52Z"
id: 1601259
url: "https://awfrun.iteye.com/blog/1601259"
---

nginx安装配置

最近部署项目用到了nginx,下面安装过程以及安装过程遇到的问题和解决方法

1.安装支持正则的pcre模块

shell:

tar zxvf pcre-8.02.tar.gz

cd pcre-8.02

./configure

make

make install

2.安装  gcc-c++（如果不存在)

yum install gcc-c++  

3.安装nginx

shell:

tar zxvf nginx-0.8.54.tar.gz

cd t ar zxvf  nginx-0.8.54

./configure --with-http\_stub\_status\_module --with-http\_gzip\_static\_module  --prefix=/opt/nginx

make

make install

ps: --prefix=/opt/nginx安装路径  --with-http\_gzip\_static\_module传输压缩模块  --with-http\_stub\_status\_module监控当前状态模块

ps:

CPU相关:

#user  nobody;

#worker\_processes 4; 

进程位置

pid        logs/nginx.pid;

4.启动&停止

/opt/nginx/sbin/nginx -V    #查看编译选项，安装模块

/opt/nginx/sbin/nginx -t  #查看配置文件是否正确

/opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf  #指定配置文件是否正确

/opt/nginx/sbin/nginx  #启动

ps -ef|grep nginx  #查看pid

kill -XXX pid 

-XXX  : QUIT:请求处理完成后关闭进程

HUP:平滑重启

USR1,USR2

ps:其它关闭方法 /opt/nginx/sbin/nginx -s stop  # 详细 -h帮助

//问题集：

安装Nginx时报错 the HTTP cache module requires md5 functions

2011-09-25 13:20

安装Nginx时报错

./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题  
yum -y install pcre-devel

错误提示：./configure: error: the HTTP cache module requires md5 functions  
from OpenSSL library.   You can either disable the module by using  
\--without-http-cache option, or install the OpenSSL library into the system,  
or build the OpenSSL library statically from the source with nginx by using  
\--with-http\_ssl\_module --with-openssl=&lt;path&gt; options.

解决办法：

yum -y install openssl openssl-devel

 

\-----------------------------------------------------------------------------------------------------------------------

下面的配置文件：

 

#user  nobody;  
#worker\_processes 4;  
#worker\_cpu\_affinity 0001 0010 0100 1000;  
worker\_processes 2;  
worker\_cpu\_affinity 0001 0010;

#error\_log  logs/error.log;  
#error\_log  logs/error.log  notice;  
#error\_log  logs/error.log  info;

pid        logs/nginx.pid;  
worker\_rlimit\_nofile 65535;

events {  
    use epoll;  
    worker\_connections  65535;  
}

http {  
    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 20m;  
    limit\_rate 1024k;  
    sendfile on;  
    tcp\_nopush     on;  
    keepalive\_timeout 65;  
    tcp\_nodelay on;  
    client\_body\_buffer\_size 512k;  
    proxy\_connect\_timeout 300;  
    proxy\_send\_timeout 300;  
    proxy\_read\_timeout 300;  
    proxy\_buffer\_size 64k;  
    proxy\_buffers 4 64k;  
    proxy\_busy\_buffers\_size 128k;  
    proxy\_temp\_file\_write\_size 128k;  
    gzip on;  
    gzip\_min\_length 1k;  
    gzip\_buffers     4 16k;  
    gzip\_http\_version 1.0;  
    gzip\_comp\_level 2;  
    gzip\_types       html css gif jpeg png js swf txt xml;  
    gzip\_vary on;  
     
     
     
   

    server {  
        listen       80;  
        server\_name  localhost;  
        access\_log off;  
        location ^~ /WEB-INF {  
                deny all;  
                 }  
                 
    location ~* \\.(htm|html|gif|jpg|jpeg|png|bmp|ico|rar|zip|java|jar|flv|swf|mid|doc|ppt|xls|pdf|mp3|wma|css|js|txt|xml)$ {  
                    root /usr/local/tomcatStone/webapps/ROOT;  
                }  
    error\_page   500 502 503 504  /50x.html;  
                 
    location = /50x.html {  
            root   html;  
        }

     location / {   
                proxy\_redirect off;   
                proxy\_set\_header Host $host;   
                proxy\_set\_header X-Real-IP $remote\_addr;   
                proxy\_set\_header X-Forwarded-For   $proxy\_add\_x\_forwarded\_for;   
                proxy\_pass http://127.0.0.1:8080;                  
        }

         
        
    }

}