系统平台: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. LeetCode——Palindrome Linked List

    Description: Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it ...

  2. 日请求亿级的QQ会员AMS平台PHP7升级实践

    版权声明:本文由PHP7升级项目组原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/74 来源:腾云阁 https://www ...

  3. Python老王视频习题答案

    基础篇2:一切变量都是数据对象的引用sys.getrefcount('test') 查看引用计数变量命名不能以数字开头编码:ascii.unicode.utf-81.阅读str对象的help文档,并解 ...

  4. Android 微信分享,分享到朋友圈与分享到好友,以及微信登陆

    extends:http://www.cnblogs.com/android100/p/Android-qq.html 一.申请你的AppID http://open.weixin.qq.com/ 友 ...

  5. jfinal关联查询给dto添加表结构以外的字段并返回的处理方式

    官网栗子: http://www.jfinal.com/doc/5-10 5.10 表关联操作 JFinal ActiveRecord 天然支持表关联操作,并不需要学习新的东西,此为无招胜有招.表关联 ...

  6. numpy基础入门

    1.Numpy是什么 很简单,Numpy是Python的一个科学计算的库,提供了矩阵运算的功能,其一般与Scipy.matplotlib一起使用.其实,list已经提供了类似于矩阵的表示形式,不过nu ...

  7. Tomcat 启动出现警告问题Setting property 'minSpar eThreads' to '25' did not find a matching property

    tomcat启动报错: Jul 19, 2017 3:10:02 PM org.apache.catalina.startup.SetAllPropertiesRule beginWARNING: [ ...

  8. 阿里云 elastic search 重启 过程

    阿里云 es 重启 elasticsearch  重启 过程 实例变更中   53.13%   准备ECS资源 已完成节点数:4/4, 进度:100%     准备容器服务 进度:100%     变 ...

  9. python https协议和InsecurePlatformWarning问题

    本人最近在学习python,今天想使用python来抓取糗事百科网站上的一些笑话故事的,由于糗事百科的网站url采取的是https协议,所以当我按照常规的方式抓取的时候,发现不行,报错了,找了很多方法 ...

  10. F(N)---hdu2802(寻找循环节)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2802 f[1] = 1; f[2] = 7; f[n] = (f[n-2] - (n-1)*(n-1) ...