关闭

Linux nginx安装和对tomcat配置

标签: nginx
405人阅读 评论(2) 收藏 举报
分类:

linux下nginx安装

./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-pcre=/home/hdic/pcre-8.35

1.下载nginx包nginx-1.9.9.tar.gz
2.解压 tar -zxvf nginx-1.9.9.tar.gz
3.设置配置参数

 - cd目录为/root/NGINX/nginx-1.9.9
 - ./configure --prefix=/usr/local/nginx

3.编译并安装

  • make && make install

4.出现错误解决方案

错误为:./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= options.
(是让你设置到源码目录,而不是编译安装后的目录)
解决办法:

yum -y install openssl openssl-devel

5.nginx启动

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

6.监控模块stub_status安装
6.1 安装
- 进入之前安装目录/root/NGINX/nginx-1.9.9
- 编译nginx,加上参数 –with-http_stub_status_module

配置指令 ./configure –prefix=/usr/local

--user=nginx 
--group=nginx
--with-http_ssl_module
--with-http_realip_module
--http-client-body-temp-path=/usr/local/var/tmp/nginx/client 
--http-proxy-temp-path=/usr/local/var/tmp/nginx/proxy 
--http-fastcgi-temp-path=/usr/local/var/tmp/nginx/fcgi 
--http-scgi-temp-path=/usr/local/var/tmp/nginx/scgi 
--http-uwsgi-temp-path=/usr/local/var/tmp/nginx/uwsgi 
--with-http_geoip_module 
--with-http_stub_status_module

6.2 配置nginx.conf

#添加配置参数
        location /nginx-status {
            stub_status on;
            access_log off;
            allow all;
        }

重启服务即可,访问地址为:http://10.96.9.105:81/nginx-status

7.nginx对tomcat配置

#user  nobody;
worker_processes  4; #cpu的数量

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

#pid        logs/nginx.pid;


events {
    worker_connections  1024;#单个后台worker process进程的最大并发链接数  
}


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;

    server {
        listen       81;
        server_name  localhost:8080;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
           # root   html;
           # index  index.html index.htm;
           proxy_pass http://localhost:8080;
        }
        #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;
        }

        #添加如下配置
        location /nginx-status {
            stub_status on;
            access_log off;
            allow all;
        }

        # 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;
    #    }
    #}

}

二、第二种安装方法

1、安装nginx之前需要安装 PCRE库的安装

最新下载地址 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

tar –zxvf pcre-8.21.tar.gz,解压目录为:pcre-8.21

然后进入到 cd pcre-8.21,进行配置、编译、安装

配置

./configure或./config

编译

make

安装

make install

2、安装zlib库安装

tar -zxvf zlib-1.2.5.tar.gz cd zlib-1.2.5

./configure

make

makeinstall

3、安装openSSL库

下载页面:http://www.openssl.org/source/

tar –zxvf openssl-1.0.0.tar.gz,解压目录为:openssl-1.0.0

然后进入到 cd openssl-1.0.0,进行配置、编译、安装

配置

./configure或./config

编译

make

安装

make install

4.以上三个库确保安装好后 接下来安装nginx

tar zxvf nginx-1.9.9.tar.gz
cd nginx-1.9.9/
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre=/home/hdic/pcre-8.35
make && make install

备注:参考网址

https://segmentfault.com/a/1190000000442242
http://blog.csdn.net/xiaofeng119/article/details/23928207
http://www.jb51.net/article/60655.htm
http://www.cnblogs.com/kunhu/p/3633002.html
http://blog.csdn.net/zhuchuangang/article/details/46042845
http://genggeng.iteye.com/blog/1181665
http://blog.csdn.net/design321/article/details/48000967
http://blog.csdn.net/yangjiehuan/article/details/7030290
http://www.server110.com/nginx/201309/1792.html
http://www.111cn.net/sys/nginx/60477.htm

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:637596次
    • 积分:7417
    • 等级:
    • 排名:第3050名
    • 原创:240篇
    • 转载:20篇
    • 译文:0篇
    • 评论:40条
    最新评论