系统平台:CentOS release 6.5 (Final) 64位。

安装编译工具及库文件

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

首先要安装 PCRE

PCRE 作用是让 Nginx 支持 Rewrite 功能。

路由重写是Web服务器中的一个很重要的基本功能。通过路由重写,可以结构化URL,更具语义化(对SEO有益)。另外,分享出去的URL可能会因程序路由变动而导致URL失效,而路由的重写可以很好的解决这类问题。

适当的使用Rewrite功能,可以更我们带来很多的好处。Nginx中Rewrite的功能是基于perl语言兼容的正则表达式,所以在编译安装nginx之前,需要安装PREC库。Nginx中Rewrite功能实现是基于ngx_http_rewrite_module,所以确保安装了此模块。

1.下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

2.解压安装包:

[root@bogon src]# tar zxvf pcre-8.35.tar.gz

3.进入安装包目录

[root@bogon src]# cd pcre-8.35

4.编译安装

[root@bogon pcre-8.35]# ./configure

[root@bogon pcre-8.35]# make && make install

5.查看pcre版本

[root@bogon pcre-8.35]# pcre-config --version

安装 Nginx

1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz

[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

2、解压安装包

[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz

3、进入安装包目录

[root@bogon src]# cd nginx-1.6.2

4、编译安装

[root@bogon nginx-1.6.2]# ./configure --prefix=/opt/module/nginx-1.6.2 --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/module/pcre-8.35(pcre安装目录)

[root@bogon nginx-1.6.2]# make && make install

安装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=<path> options.

解决办法:

yum -y install openssl openssl-devel

总结:

yum -y install pcre-devel openssl openssl-devel

5、查看nginx版本

[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v

到此,nginx安装完成。

 Nginx 配置

创建 Nginx 运行使用的用户 www:

[root@bogon conf]# /usr/sbin/groupadd www 

[root@bogon conf]# /usr/sbin/useradd -g www www

配置nginx.conf ,将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容

[root@bogon conf]#  cat /usr/local/webserver/nginx/conf/nginx.conf
#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  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;

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

检查配置文件ngnix.conf的正确性命令:

[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t

启动 Nginx

Nginx 启动命令如下:

[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx

如果报错找不到error和access错误日志的路径,则在nginx安装目录下新建一个logs文件夹就可以搞定

访问站点

从浏览器访问我们配置的站点ip:

192.168.0.XXX

Nginx 其他命令

以下包含了 Nginx 常用的几个命令:

/usr/local/webserver/nginx/sbin/nginx -s reload            # 重新载入配置文件

/usr/local/webserver/nginx/sbin/nginx -s reopen            # 重启 Nginx

/usr/local/webserver/nginx/sbin/nginx -s stop              # 停止 Nginx

修改nginx.conf 并重启

1.把nginx.conf修改为:

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

pid /usr/local/webserver/nginx/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;

# 配置web集群

    upstream bakend {

#ip_hash;

         server 192.168.0.204:8080 weight=1;

        server 192.168.0.170:8080 weight=1;

    }

    server {

        listen       80;

        server_name  localhost;

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ {

#proxy_pass http://192.168.0.170:8080;

proxy_pass http://bakend;

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_redirect off;

}

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        location / {

             #proxy_pass   http://192.168.0.170:8080/;

proxy_pass http://bakend/;

         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_redirect off;

}

    }

}

2.重启Nginx

/usr/local/webserver/nginx/sbin/nginx -s reopen

3. 从浏览器访问我们配置的站点:192.168.0.XXX如下图 部署成功

【安装】Nginx安装的更多相关文章

  1. CentOS安装Nginx安装详解

    一.准备工作,安装依赖包,缺一不可!(推荐先用命令查看自己是否已经安装一下软件,确认没有再安装) --------------------------------------------------- ...

  2. Linux 安装 nginx 安装PCRE库

    PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库.这些在执行正规表达式模式匹配时用与Perl 5同样的语法和语义是 ...

  3. Mac下用brew安装nginx

    1. nginx nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TC ...

  4. git和nginx安装

    原始地址: https://www.zybuluo.com/freeethy/note/192109 git安装 设置git的username和email (注册gitlab的账号密码) $$ git ...

  5. CentOS7.0安装Nginx 1.7.9

    一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...

  6. CentOS 6.5 安装Nginx 1.7.4

    一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...

  7. centos 安装nginx

    centos 安装nginx 安装依赖 更换源 yum install http://mirrors.163.com/centos/6.8/extras/x86_64/Packages/epel-re ...

  8. (转)Centos7 Nginx安装

    场景:工作中使用的suse,因为系统可可查资料太少,且系统中一些功能的确实,导致很多集群中功能无法顺利测试通过,在Centos上面进行测试,能够更快的熟悉项目的架构过程! 1 安装准备 首先由于ngi ...

  9. CentOS7 安装Nginx+MySQL

    首先我们需要安装nginx的yum源 [root@AD ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-releas ...

  10. CentOS7上安装Nginx、PHP、MySQL

    一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...

随机推荐

  1. 借助腾讯云CDN开启全站https及问题解决分享

    版权声明:本文由张戈原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/78 来源:腾云阁 https://www.qcloud ...

  2. js:{}与new Object()的区别是什么

    var a = {}; var b = new Object(); 这两种创建对象方式,从测试效果来看,{}会快一点. {} 这个叫做对象字面量 如果new Object()中没有传入参数,与{}是一 ...

  3. HFS的远程命令执行漏洞(RCE)

    一.HFS漏洞 1.影响版本 : 2.3c以前的2.3x版本 2.HFS: HFS是HTTP File Server,国外的一款HTTP 文件服务器软件,简单易上手. 3.漏洞描述: HTTP Fil ...

  4. js表单的focus()与blur()方法

    前段时间在多文本输入textarea中遇到点小问题,textarea在HTML是没有value属性的,但在js里的可以获取其value值. textarea禁止拉伸resize:none; (为了兼容 ...

  5. ATDD和TDD的区别是什么?

    最近看到一个新名词"ATDD",全称"Acceptance Test Driven Development ",中文称"验收测试驱动开发". ...

  6. java如何使用base64生成图片文件

    import org.apache.commons.codec.binary.Base64; public static void decodeFile(String base64Str,File f ...

  7. linux的ls命令输出结果的逐条解释

    转自:http://blog.csdn.net/god123209/article/details/7193485 ls 命令的含义是list显示当前目录中的文件名字.注意不加参数它显示除隐藏文件外的 ...

  8. linux对文件某列求和

    对文件某列求和: -F,用,号分隔,求第3行的和 awk -F,  '{sum += $3};END {print sum}' test

  9. 04.ActiveMQ与Spring JMS整合

        SpringJMS使用参考:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jms.html ...

  10. java之面向对象三大特征(封装,继承,多态)

    一.封装 封装是指将对象的状态信息隐藏在对象内部,不允许外部程序直接访问对象内部信息,而是通过该类提供的对外方法进行内部信息的操作和访问. 封装可以达到以下目的: 1)隐藏类的实现细节 2)让使用者只 ...