Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。

一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。

1.选定源码目录

选定目录 /usr/local/

cd /usr/local/

2.安装PCRE库

cd /usr/local/

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.tar.gz

tar -zxvf pcre-8.21.tar.gz

cd pcre-8.21

./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;

}

}

}

}

大神

     

Nginx安装部署的更多相关文章

  1. Nginx安装部署与测试

    场景:项目需要部署在生产环境中,这些新的工具都需要在生产环境中去实践练习.有时间再部署一套ELK的日志分析系统,这样的系统才算具有一定的应用价值. 1 Nginx安装 用root用户安装,采用源代码编 ...

  2. nginx安装部署(支持https)

    1      安装环境准备 1.1   准备环境清单 以下是基本环境清单列表: 软件名称 版本号 说明信息 Linux CentOS 6.7 部署机器只需为Linux系统即可,无严格要求 1.2   ...

  3. 云服务器内,nginx安装部署,Xshell,Xftp安装

    nginx部署 三丰云云服务器,安装nginx nginx部署 在宝塔面板,添加Nginx安装,一般进来会默认推荐安装几款软件,mysql等,暂时可以后面再装,先把nginx装上去,去感受将前端页面放 ...

  4. Nginx安装部署以及配置文件解析

    Nginx 中的 Location 指令 是NginxHttpCoreModule中重要指令.Location 指令,是用来为匹配的 URI 进行配置,URI 即语法中的”/uri/”,可以是字符串或 ...

  5. linux centos7 nginx 安装部署和配置

    1/什么是NginxNginx("enginex")是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器,在高连接并发的情况下Nginx是Apac ...

  6. Linux中Nginx安装部署

    前言 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sys ...

  7. Centos 6.5 下Nginx安装部署https服务器

    一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩.1.选定源码目录选定目录 /usr/local/cd /usr/local/2.安装PCRE库cd /usr/ ...

  8. nginx安装部署+增加媒体播放模块

    nginx安装很简单,但是有的时候是已经安装的nginx ,升级增加nginx 模块功能. 最近公司要nginx增加一个可以播放 MP4的模块,安装还算顺利,不说废话上命令. 1 安装依赖 yum i ...

  9. Nginx安装部署!

    安装Nginx方法一:利用u盘导入Nginx软件包 二nginx -t 用于检测配置文件语法 如下报错1:配置文件43行出现错误 [root@www ~]# nginx -tnginx: [emerg ...

随机推荐

  1. 自动设置iframe大小的jQuery代码

    自动设置iframe的宽度,如何用jquery来实现呢? 代码: <iframe src="main_folder.aspx" class="global_main ...

  2. Xaml代码格式设置

    Xaml格式化后属性分行显示的设置方法为 找到Tools->Text Editor->Xaml->Formatting->Spacing,选择Position each att ...

  3. Oracle 的证也会过期咯

    How does this recertification requirement affect me? If your Database Certification credential is re ...

  4. WPF中的Style

    一.Style基础知识 构成Style最重要的两种元素是Setter和Trigger Setter类帮助我们设置控件的静态外观风格 Trigger类帮助我们设置控件的行为风格 Setter类的Prop ...

  5. linux驱动路径

    1. 按键驱动 \drivers\input\keyboard\utu2440_buttons.c 2. LED驱动 \drivers\char\utu2440-led.c 3. DM9000网卡驱动 ...

  6. 【Jetlang】一个高性能的Java线程库

    actor  Jetlang 提供了一个高性能的Java线程库,该库是 JDK 1.5 中的 java.util.concurrent 包的补充,可用于基于并发消息机制的应用. .net的MS CCR ...

  7. .net如何调试dll

    引用"谢绝关注的BLOG" http://blog.sina.com.cn/s/blog_50cc0ffd0100cqhp.html 在同一个解决方案中一定要将调用DLL文件的工程 ...

  8. 好项目烂架构的问题,四年coder的吐槽

    四年多码农,毕业后在一家小私企做前端:(初始asp.net,对oo有了比较深切的理解:处于对某空间的效仿,对前端技术架构理解的比较透彻): 在这家公司混了4个月之后跳出来想自己单干: 自己接了个小项目 ...

  9. 在唯一密钥属性“value”设置为“Default.aspx”时,无法添加类型为“add”的重复集合项

    环境:windows server 2012  asp.net 找到网站目录:wwwroot ,打开web.config文件,在 在<files>与</files>之间加入代码 ...

  10. Intellij IDEA14 下添加ExtJS提示支持

    前言: 虽然Interlij IDEA比起Eclipse对待EXT更为支持,但自己上手后总不能达到Intellij 开发ExtJS 应用指南(http://blog.csdn.net/s4640368 ...