Nginx反向代理服务器配置教程一,系统架构
二,Nginx安装
系统环境与组件:
Centos 6.6 x64
nginx v1.92
gcc
openssl-devel
pcre-devel
libevent
1,更换国内源
1)、下载新源及将本地源备份
# cd /pos.d/
# wget mirrors.163/.po
# po.backup
# po
2)、yum源更新
# yum clean all && yum makecache && yum update -y
3)、完成
2,安装依赖包
1)
# yum -y install gcc
# yum -y install openssl openssl-devel
# yum -y install pcre-devel
检查安装结果命令:
# rpm -qa |grep gcc
2)安装libevent
libevent是一个事件触发的网络库,适用于windows、linux、bsd等多种平台,内部使用select、epoll、kqueue等系统调用管理事件机制。著名分布式缓存软件memcached也是libevent based,而且libevent在使用上可以做到跨平台,而且根据libevent上公布的数据统计,似乎也有着非凡的性能。下载地址:/
安装步骤:
# cd ~ #进入用户主目录,软件包都保存在这里。
linux离线安装nginx详细教程# wget cznic.dl.sourceforge/project/levent/libevent/libevent-2.1/libevent-2.1.
# tar –xvf libevent-2.1.
# cd libevent-2.1.4-alpha
# ./configure
# make
# make install
3,相关用户及目录建立
1)建立运行nginx的用户与用户组
# groupadd -r nginx
# useradd -r -g nginx -s /bin/false -M nginx
2)建立安装nginx要用到的临时文件目录
#mkdir -p/var/tmp/nginx/proxy
4,Nginx安装
1)下载nginx-1.9.,上传至/root目录。
# cd ~
# tar –xvf nginx-1.9.
# cd nginx-1.9.2
/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-ht tp_gzip_static_module --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --with-pcre
# make && make install
参数释义:
--prefix=/usr
#安装完成将自动生成目录usr,而且该软件任何的文档都被复制到这个目录
--sbin-path=/usr/sbin/nginx Nginx
#可执行文件安装路径。只能安装时指定,如果没有指定,默认为<prefix>/sbin/nginx。
--conf-path=/etc/f
# 在没有给定-c选项下默认的f的路径。如果没有指定,默认为<prefix>/f。
--error-log-path=/var/log/nginx/error.log
# 在f中没有指定error_log指令的情况下,默认的错误日志的路径。如果没有指定,默认为<prefix>/logs/error.log。
--http-log-path=/var/log/nginx/access.log
# 在f中没有指定access_log指令的情况下,默认的访问日志的路径。如果没有指定,默认为<prefix>/logs/access.log。
--pid-path=/var/run/nginx/nginx.pid
# 在f中没有指定pid指令的情况下,默认的nginx.pid的路径。如果没有指定,默认为<prefix>/logs/nginx.pid。--lock-path=/var/lock/nginx.lock
# nginx.lock文件的路径。
--user=nginx
# 在f中没有指定user指令的情况下,默认的nginx使用的用户。如果没有指定,默认为nobody。
--group=nginx
# 在f中没有指定user指令的情况下,默认的nginx使用的组。如果没有指定,默认为nobody。
--with-http_ssl_module
# 开启HTTP SSL模块,使NGINX可以支持HTTPS请求。这个模块需要已经安装了OPENSSL,在DEBIAN上是libssl --with-http_flv_module
# 启用ngx_http_flv_module,模块ngx_http_flv_module为Flash Video(FLV)文件提供服务端伪流媒体支持
--with-http_stub_status_module
# 启用"server status" 页
--with-http_gzip_static_module
# 启用ngx_http_gzip_module,静态压缩
--http-proxy-temp-path=/var/tmp/nginx/proxy/
# 设置路径http代理临时文件
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
# 设置路径的http FastCGI的临时文件
--with-pcre
# 启用正则表达式及rewrite模块
安装完毕记住以下路径:
nginx path prefix: "/usr"
nginx binary file: "/usr/sbin/nginx"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/f"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "/var/tmp/nginx/proxy/"
nginx http fastcgi temporary files: "/var/tmp/nginx/fcgi/"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
注意:后面的各种配件文件中要用到的路径都与这里保持一致。
5,运行nginx测试网站
1)运行nginx服务
# nginx
2)打开192.168.1.86,如果能看到如下图,那么配置成功;
3)如果打不开,可能是防火墙端口没开,可以关闭防火墙后试一下,具体如何开启80端口,本教程不做介绍;# service iptables stop
三,配置nginx反向代理服务
1、修改nginx服务配置文件:
# vi /etc/f
配置文件内容如下:
>>>>>>>>>>>>>>
# 设置运行nginx的用户
user nginx nginx;
# 这里设置为当前CPU核心数
worker_processes 1;
# nginx运行日志
error_log /var/log/nginx/error.log;
# nginx运行进程ID存储路径
pid /var/run/nginx/nginx.pid;
# 每个nginx进程打开文件描述符最大数目
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
pes;
default_type application/octet-stream;
# 站点配置文件路径
include /etc/nginx/conf.d/*.conf;
# 开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off
sendfile on;
# 长连接超时时间,单位是秒
keepalive_timeout 120;
# 开启gzip压缩输出
gzip on;
# 缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户
client_max_body_size 50m;
# 缓冲区代理缓冲用户端请求的最大字节数
client_body_buffer_size 256k;
# 设置请求头的超时时间
client_header_timeout 10;
# 设置请求体的超时时间
client_body_timeout 10;
# 指定客户端的响应超时时间
send_timeout 10;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。

发表评论