首页 > Nginx 在centos linux 安装、部署完整步骤并测试通过

Nginx 在centos linux 安装、部署完整步骤并测试通过

需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。

1.选定源码目录

选定目录 /usr/local/

 

cd /usr/local/

2.安装PCRE库

cd /usr/local/

wget http://exim.mirror.fr/pcre/pcre-8.02.tar.gz

tar -zxvf pcre-8.02.tar.gz

cd pcre-8.02

./configure && make  && make install

 

3.安装zlib库

cd /usr/local/ 

wget http://zlib.net/zlib-1.2.8.tar.gz

tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8

./configure

make

make install

 

4.安装ssl

 

cd /usr/local/

wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz

tar -zxvf openssl-1.0.1c.tar.gz

./config

make

make install

 

5.安装nginx

 

Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:

 

cd /usr/local/

wget http://nginx.org/download/nginx-1.2.8.tar.gz

tar -zxvf nginx-1.2.8.tar.gz

cd nginx-1.2.8  

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

make

make install

 

--with-pcre=/usr/src/pcre-8.21 指的是pcre-8.21 的源码路径。

--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源码路径。

 

6.启动

确保系统的 80 端口没被其他程序占用,

/usr/local/nginx/sbin/nginx

 

检查是否启动成功:

netstat -ano|grep 80 有结果输入说明启动成功

 

 

打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

 

7.重启

/usr/local/nginx/sbin/nginx –s reload

 

8.修改配置文件

cd /usr/local/nginx/conf

vi nginx.conf

 

9.常用配置

#nginx运行用户和组

user    www www;  

#启动进程,通常设置成和cpu的数量相等

worker_processes  4;

 

#全局错误日志及PID文件

pid /var/run/nginx.pid;

error_log  /var/log/nginx/error.log;

 

events {

        #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能

use epoll;

                   #单个后台worker process进程的最大并发链接数

        worker_connections  10240;

}

#设定http服务器,利用它的反向代理功能提供负载均衡支持

http {

        include       mime.types;

 

        default_type  application/octet-stream;

 

         error_page 400 403 500 502 503 504  /50x.html;

 

        index index.html index.shtml

 

        autoindex off;

 

         fastcgi_intercept_errors on;

 

        sendfile        on;

 

        # These are good default values.

        tcp_nopush      on;

        tcp_nodelay     off;

 

        # output compression saves bandwidth

        gzip  off;

         #gzip_static on;

        #gzip_min_length  1k;

        gzip_http_version 1.0;

        gzip_comp_level 2;

        gzip_buffers  4 16k;

        gzip_proxied any;

        gzip_disable "MSIE [1-6].";

        gzip_types  text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;

        #gzip_vary on;

 

        server_name_in_redirect off;

 

#设定负载均衡的服务器列表

        upstream portals {

                  server 172.16.68.134:8082 max_fails=2 fail_timeout=30s;

                  server 172.16.68.135:8082 max_fails=2 fail_timeout=30s;

                            server 172.16.68.136:8082 max_fails=2 fail_timeout=30s;

                  server 172.16.68.137:8082 max_fails=2 fail_timeout=30s;

        }

 

        #upstream overflow {

         #       server 10.248.6.34:8090 max_fails=2 fail_timeout=30s;       

         #       server 10.248.6.45:8080 max_fails=2 fail_timeout=30s;       

        #}

 

        server {

                                     #侦听8080端口

                listen       8080;

                server_name  127.0.0.1;

 

                   #403、404页面重定向地址

                   error_page  403 = http://www.e100.cn/ebiz/other/217/403.html;

                   error_page  404 = http://www.e100.cn/ebiz/other/218/404.html;

                   proxy_connect_timeout      90;

                   proxy_send_timeout         180;

                   proxy_read_timeout         180;

 

                   proxy_buffer_size 64k;

                   proxy_buffers 4 128k;

                   proxy_busy_buffers_size 128k;

 

 

                   client_header_buffer_size 16k;

                   large_client_header_buffers 4 64k;

 

                #proxy_send_timeout         3m;

                #proxy_read_timeout         3m;

                #proxy_buffer_size          4k;

                #proxy_buffers              4 32k;

 

                proxy_set_header Host $http_host;

                proxy_max_temp_file_size 0;

                #proxy_hide_header Set-Cookie;

                  

         #       if ($host != 'www.e100.cn' ) {

         #                rewrite ^/(.*)$ http://www.e100.cn/$1 permanent;

         #       }

 

 

               location / {

                       deny all;

               }

 

                   location ~ ^/resource/res/img/blue/space.gif {

                    proxy_pass http://tecopera;

               }

 

               location = / {

                   rewrite ^(.*)$  /ebiz/event/517.html last;

               }

 

 

 

                   location = /ebiz/event/517.html {

                    add_header Vary Accept-Encoding;

                    root /data/web/html;

                    expires 10m;

               }

 

 

 

 

               location = /check.html {

                    root /usr/local/nginx/html/;

                    access_log off;

               }

 

               location = /50x.html {

                    root /usr/local/nginx/html/;

                    expires 1m;

                    access_log off;

               }

 

 

              location = /index.html {

                       add_header Vary Accept-Encoding;

#定义服务器的默认网站根目录位置

                    root /data/web/html/ebiz;

                    expires 10m;

               }

#定义反向代理访问名称

                   location ~ ^/ecps-portal/* {

                   # expires 10m;

#重定向集群名称

                    proxy_pass http://portals;

                    #proxy_pass http://172.16.68.134:8082;

               }

 

                   location ~ ^/fetionLogin/* {

                   # expires 10m;

                    proxy_pass http://portals;

                    #proxy_pass http://172.16.68.134:8082;

                }

 

                   #location  ~ ^/business/* {                                                                      

                #   # expires 10m;                                                                                

                #    proxy_pass http://172.16.68.132:8088;                                                                   

                #    #proxy_pass http://172.16.68.134:8082;                                                       

                #}

 

                   location ~ ^/rsmanager/* {

                    expires 10m;

                    root /data/web/;

                    #proxy_pass http://rsm;

               }

#定义nginx处理的页面后缀

                   location ~* (.*).(jpg|gif|htm|html|png|js|css)$  {

                            root /data/web/html/;

#页面缓存时间为10分钟

                         expires 10m;

                   }

 

#设定查看Nginx状态的地址     

               location ~* ^/NginxStatus/ {

                    stub_status on;

                    access_log off;

                    allow 10.1.252.126;

                    allow 10.248.6.49;

                    allow 127.0.0.1;

                    deny all;

               }

         #       error_page   405 =200 @405;

         #       location @405

         #       {

         #                proxy_pass http://10.248.6.45:8080;

         #       }  

 

               access_log  /data/logs/nginx/access.log combined;

               error_log   /data/logs/nginx/error.log;

        }

         server {

                listen       8082;

 

                server_name  _;

               location = /check.html {

                    root /usr/local/nginx/html/;

                    access_log off;

               }

                  

        }

         server {

                   listen       8088;

                   server_name  _;

                   location ~ ^/* {

                   root /data/web/b2bhtml/;

                   access_log off;

         }                

         }

        server {

                listen       9082;

                server_name  _;

 

        #        location ~ ^/resource/* {

        #            expires 10m;

         #           root /data/web/html/;

         #       }

 

                location  / {

                     root /data/web/html/sysMaintain/;

                       if (!-f $request_filename) {

                            rewrite ^/(.*)$ /sysMaintain.html last;

                           }

                }

        }

 

}

转载于:https://www.cnblogs.com/kool/p/6696086.html

更多相关:

  • ng g s services/http  app.module.ts ... @NgModule({declarations: [...],imports: [...HttpClientModule,//这个很重紧要,没有就会报错],providers: [],bootstrap: [AppComponent] }) expor...

  • set-misc-nginx-module模块是标准的HttpRewriteModule指令的扩展,提供更多的功能,如URI转义与非转义、JSON引述、Hexadecimal/MD5/SHA1/Base32/Base64编码与解码、随机数等等。在后面的应用中,都将会接触使用到这个模块的。该模块是由章亦春先生开发的,他开发的其他模块应用...

  • 该源码包是MySQL-python-1.2.4b4.tar.gz 从2013-06-28以来一直没有更新,注意该网站可以区分访问的终端类型是Windows还是Linux之类的,从而返回的源码包格式不一样。 在CentOS上的安装方法是 http://www.cnblogs.com/jackluo/p/3559978.html...

  • ATS默认提供了对Referer头的http request的防盗链功能,主要应用于图片,对视频等会使用级别更高的防盗链功能,比如事先约定好key,采用md5或HMAC-Sha1算法加密等。 在remap.config中按如下格式设置: map_with_referer client-URL origin-server-URL re...

  • 测试大文件下载 curl -I "http://resource.tsk.erya100.com/TS/flv/TS180/5836/9.flv?t=1430796561727" 单条转发模式in per remap mode 在remap.config中添加一条 map http://resource.tsk.e...

  • echo-nginx-module是一个第三方模块,在nginx源码中没有,但是OpenResty中有,它为nginx.conf带来了echo,sleep,time等多个类似bash的强大命令。 目前最新版本是v0.61 安装指南参见 https://github.com/openresty/echo-nginx-modul...

  • vim /etc/init.d/nginx   粘贴 #!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-...

  • 1.下载nginx   方法一   wget http://nginx.org/download/nginx-1.11.6.tar.gz   方法二   http://nginx.org/en/download.html在Nginx官网手动下载 2.解压nginx的gz包   tar -zxvf nginx-1.11.6.t...

  • 本文档记录了完全使用最新源码来编译安装nginx最新版1.10.3,所有的依赖也是最新的,便于第三方nginx模块开发 假定使用root身份安装 目前最新的源码地址汇总 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz http:/...

  • 为了自己的ThinkPad T420上面的Ubuntu可以使用openresty开发,我特地记录一下安装过程: 安装依赖包 apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make build-essential 下载源码并...

  • 根据工作需要,现在需要安装nginx服务器,本来可以直接安装别人制作好的rpm包的,但是本着爱折腾和时刻尝鲜的精神,我决定从官网下载最新的nginx源码来安装,下面记录了我的安装过程。 下面的安装假定是以root用户登录并执行 1.安装依赖库 这些依赖库主要有g++、gcc、openssl-devel、pcre-devel和zl...