2022年Nginx反向代理服务器配置基础教程 .pdf





《2022年Nginx反向代理服务器配置基础教程 .pdf》由会员分享,可在线阅读,更多相关《2022年Nginx反向代理服务器配置基础教程 .pdf(11页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Nginx反向代理服务器配置教程一,系统架构二,Nginx安装系统环境与组件:Centos 6.6 x64 nginx v1.92 gcc openssl-devel pcre-devel libevent 1, 更换国内源1)、下载新源及将本地源备份# cd /etc/yum.repos.d/ # wget http:/ # mv CentOS-Base.repo CentOS-Base.repo.backup # mv CentOS6-Base-163.repo CentOS-Base.repo 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - -
2、- - - - - 名师精心整理 - - - - - - - 第 1 页,共 11 页 - - - - - - - - - 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 、l
3、inux、 bsd 等多种平台,内部使用select、epoll、kqueue 等系统调用管理事件机制。著名分布式缓存软件memcached 也是 libevent based,而且 libevent 在使用上可以做到跨平台,而且根据libevent 官方网站上公布的数据统计,似乎也有着非凡的性能。官网下载地址:http:/libevent.org/ 安装步骤:# cd #进入用户主目录,软件包都保存在这里。# wget http:/ # tar xvf libevent-2.1.4-alpha.tar.gz # cd libevent-2.1.4-alpha # ./configure #
4、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.2.tar.gz,上传至 /root 目录。# cd # tar xvf nginx-1.9.2.tar.gz # cd nginx-1.9.2 #./configure -prefix=/usr -sbin-p
5、ath=/usr/sbin/nginx -conf-path=/etc/nginx/nginx.conf -error-log-path=/var/log/nginx名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 11 页 - - - - - - - - - /error.log -http-log-path=/var/log/nginx/access.log -pid-path=/var/run/nginx/nginx.pid -lock-path=/var/lock/
6、nginx.lock-user=nginx -group=nginx -with-http_ssl_module -with-http_flv_module -with-http_stub_status_module -with-http_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,而且该软件
7、任何的文档都被复制到这个目录-sbin-path=/usr/sbin/nginx Nginx #可执行文件安装路径。只能安装时指定,如果没有指定,默认为/sbin/nginx 。-conf-path=/etc/nginx/nginx.conf# 在没有给定 -c 选项下默认的nginx.conf 的路径。如果没有指定,默认为/conf/nginx.conf 。-error-log-path=/var/log/nginx/error.log# 在nginx.conf中 没 有 指 定error_log指 令 的 情 况 下 , 默 认 的 错 误 日 志 的 路 径 。 如 果 没 有 指 定
8、, 默 认 为/logs/error.log 。-http-log-path=/var/log/nginx/access.log# 在nginx.conf 中没有指定access_log 指令的情况下,默认的访问日志的路径。如果没有指定,默认为/logs/access.log 。-pid-path=/var/run/nginx/nginx.pid# 在 nginx.conf 中没有指定pid 指令的情况下, 默认的 nginx.pid 的路径。如果没有指定, 默认为 /logs/nginx.pid 。-lock-path=/var/lock/nginx.lock# nginx.lock 文件的
9、路径。-user=nginx# 在 nginx.conf 中没有指定user 指令的情况下,默认的nginx 使用的用户。如果没有指定,默认为nobody。-group=nginx# 在 nginx.conf 中没有指定user 指令的情况下,默认的nginx 使用的组。如果没有指定,默认为nobody。-with-http_ssl_module# 开启 HTTP SSL 模块,使NGINX可以支持HTTPS请求。这个模块需要已经安装了OPENSSL ,在 DEBIAN上是 libssl -with-http_flv_module# 启用ngx_http_flv_module ,模块 ngx_
10、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# 启用正则
11、表达式及rewrite 模块安装完毕记住以下路径: nginx path prefix: /usr nginx binary file: /usr/sbin/nginx nginx configuration prefix: /etc/nginx nginx configuration file: /etc/nginx/nginx.conf nginx pid file: /var/run/nginx/nginx.pid 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 1
12、1 页 - - - - - - - - - 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/
13、 nginx http uwsgi temporary files: uwsgi_temp nginx http scgi temporary files: scgi_temp 注意:后面的各种配件文件中要用到的路径都与这里保持一致。5, 运行 nginx 测试网站1)运行 nginx 服务# nginx 2)打开 http:/192.168.1.86 ,如果能看到如下图,那么配置成功;3)如果打不开,可能是防火墙端口没开,可以关闭防火墙后试一下,具体如何开启80 端口,本教程不做介绍;# service iptables stop 三,配置 nginx反向代理服务1、 修改 nginx 服务
14、配置文件:# vi /etc/nginx/nginx.conf 配置文件内容如下:# # 设置运行 nginx 的用户user nginx nginx; # 这里设置为当前CPU核心数worker_processes 1; # nginx 运行日志error_log /var/log/nginx/error.log; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 11 页 - - - - - - - - - # nginx 运行进程ID 存储路径pid /var/run
15、/nginx/nginx.pid; # 每个 nginx 进程打开文件描述符最大数目worker_rlimit_nofile 65535; events use epoll; worker_connections 65535; http include mime.types; default_type application/octet-stream; # 站点配置文件路径include /etc/nginx/conf.d/*.conf; # 开启高效文件传输模式,sendfile 指令指定nginx 是否调用sendfile 函数来输出文件,对于普通应用设为on,如果用来进行下载等应用磁盘I
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年Nginx反向代理服务器配置基础教程 2022 Nginx 反向 代理服务器 配置 基础教程

限制150内