nginx安装配置

来源:互联网 发布:游戏编程软件拼音 编辑:程序博客网 时间:2024/06/05 05:00
Nginx 安装
系统环境与组件:
Centos 6.6 x64
nginx v1.92
gcc
openssl-devel
pcre-devel
libevent
1,  更换国内源
1)、下载新源及将本地源备份
# cd /etc/yum.repos.d/
# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
# mv CentOS-Base.repo CentOS-Base.repo.backup
# mv CentOS6-Base-163.repo CentOS-Base.repo
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 官方网站上公布的数据统计,似乎也有着非凡的性能。官网下载地址:http://libevent.org/
安装步骤:
# cd ~      #进入用户主目录,软件包都保存在这里。
# wget http://cznic.dl.sourceforge.net/project/levent/libevent/libevent-2.1/libevent-2.1.4-alpha.tar.gz
# tar –xvf libevent-2.1.4-alpha.tar.gz
# 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.2.tar.gz,上传至/root 目录。
# cd ~
# tar –xvf nginx-1.9.2.tar.gz
# cd nginx-1.9.2
#./configure  --prefix=/usr  --sbin-path=/usr/sbin/nginx  --conf-path=/etc/nginx/nginx.conf  --error-log-path=/var/log/nginx
/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/nginx/nginx.conf
#  在没有给定-c 选项下默认的 nginx.conf 的路径。如果没有指定,默认为<prefix>/conf/nginx.conf。
--error-log-path=/var/log/nginx/error.log
#  在 nginx.conf 中没有指定 error_log 指令的情况下,默认的错误日志的路径。如果没有指定,默认为
<prefix>/logs/error.log。
--http-log-path=/var/log/nginx/access.log
#  在 nginx.conf 中没有指定 access_log 指令的情况下,默认的访问日志的路径。如果没有指定,默认为
<prefix>/logs/access.log。
--pid-path=/var/run/nginx/nginx.pid
#  在 nginx.conf 中没有指定 pid 指令的情况下,默认的 nginx.pid 的路径。如果没有指定,默认为<prefix>/logs/nginx.pid。
--lock-path=/var/lock/nginx.lock
# nginx.lock 文件的路径。
--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_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/nginx/nginx.conf"
nginx pid file: "/var/run/nginx/nginx.pid" 
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)打开 http://192.168.1.86,如果能看到如下图,那么配置成功;


3)如果打不开,可能是防火墙端口没开,可以关闭防火墙后试一下.
# service iptables stop


0 0