nginx安装手册

上传人:jiups****uk12 文档编号:40501979 上传时间:2018-05-26 格式:DOC 页数:8 大小:90.50KB
返回 下载 相关 举报
nginx安装手册_第1页
第1页 / 共8页
nginx安装手册_第2页
第2页 / 共8页
nginx安装手册_第3页
第3页 / 共8页
nginx安装手册_第4页
第4页 / 共8页
nginx安装手册_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《nginx安装手册》由会员分享,可在线阅读,更多相关《nginx安装手册(8页珍藏版)》请在金锄头文库上搜索。

1、Nginx 安装手册1 1 nginx 安装环境安装环境nginx 是 C 语言开发,建议在 linux 上运行,本教程使用 Centos6.5 作为安装环境。 gcc 安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境, 需要安装 gcc:yum install gcc-c+ PCRE PCRE(Perl Compatible Regular Expressions)是一个 Perl 库,包括 perl 兼容的正则表达式 库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库。 yum i

2、nstall -y pcre pcre-devel注:pcre-devel 是使用 pcre 开发的一个二次开发库。nginx 也需要此库。 zlibzlib 库提供了很多种压缩和解压缩的方式,nginx 使用 zlib 对 http 包的内容进行 gzip, 所以需要在 linux 上安装 zlib 库。 yum install -y zlib zlib-developensslOpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证 书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。 nginx 不仅支持 http 协议,还支持 https

3、(即在 ssl 协议上传输 http),所以需要在 linux 安装 openssl 库。 yum install -y openssl openssl-devel2 2 编译安装编译安装将 nginx-1.8.0.tar.gz 拷贝至 linux 服务器。解压: tar -zxvf nginx-1.8.0.tar.gz cd nginx-1.8.01、 configure ./configure -help 查询详细参数(参考本教程附录部分:nginx 编译参数)参数设置如下: ./configure -prefix=/usr/local/nginx -pid-path=/var/run/n

4、ginx/nginx.pid -lock-path=/var/lock/nginx.lock -error-log-path=/var/log/nginx/error.log -http-log-path=/var/log/nginx/access.log -with-http_gzip_static_module -http-client-body-temp-path=/var/temp/nginx/client -http-proxy-temp-path=/var/temp/nginx/proxy -http-fastcgi-temp-path=/var/temp/nginx/fastcg

5、i -http-uwsgi-temp-path=/var/temp/nginx/uwsgi -http-scgi-temp-path=/var/temp/nginx/scgi注意:上边将临时文件目录指定为注意:上边将临时文件目录指定为/var/temp/nginx,需要在,需要在/var 下创建下创建 temp 及及 nginx 目录目录rootbogon nginx-1.8.0# mkdir /var/temp/nginx -p2、 编译安装 make make install安装成功查看安装目录 :3 3 启动启动 nginxcd /usr/local/nginx/sbin/ ./ngin

6、x 查询 nginx 进程:15098 是 nginx 主进程的进程 id,15099 是 nginx 工作进程的进程 id注意:执行注意:执行./nginx 启动启动 nginx,这里可以,这里可以-c 指定加载的指定加载的 nginx 配置文件,如下:配置文件,如下: ./nginx -c /usr/local/nginx/conf/nginx.conf如果不指定如果不指定-c,nginx 在启动时默认加载在启动时默认加载 conf/nginx.conf 文件,此文件的地址也可以在编译文件,此文件的地址也可以在编译 安装安装 nginx 时指定时指定./configure 的参数(的参数(

7、-conf-path= 指向配置文件(指向配置文件(nginx.conf)4 4 停止停止 nginx方式 1,快速停止: cd /usr/local/nginx/sbin ./nginx -s stop此方式相当于先查出 nginx 进程 id 再使用 kill 命令强制杀掉进程。方式 2,完整停止(建议使用): cd /usr/local/nginx/sbin ./nginx -s quit此方式停止步骤是待 nginx 进程处理任务完毕进行停止。5 5 重启重启 nginx方式 1,先停止再启动(建议使用): 对 nginx 进行重启相当于先停止 nginx 再启动 nginx,即先执行

8、停止命令再执行启动命令。 如下: ./nginx -s quit ./nginx方式 2,重新加载配置文件: 当 nginx 的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload 不 用先停止 nginx 再启动 nginx 即可将配置信息在 nginx 中生效,如下: ./nginx -s reload6 6 测试测试nginx 安装成功,启动 nginx,即可访问虚拟机上的 nginx:到这说明 nginx 上安装成功。若无法访问, 可能是 Linux 的防火墙的问题: 1.修改文件 vim /etc/sysconfig/iptables2.

9、关闭防火墙 sevice iptables stop3.或CentOS7 默认使用的是 firewall 作为防火墙,这里改为 iptables 防火墙 1、关闭 firewall: systemctl stop firewalld.service #停止 firewall systemctl disable firewalld.service #禁止 firewall 开机启动2、安装 iptables 防火墙 yum install iptables-services #安装3、修改文件配置允许 80 端口 vi /etc/sysconfig/iptables #编辑防火墙配置文件 按 i

10、 进入文本编辑 在原文档中找到 -A INPUT -m state state NEW -m tcp -p tcp dport 22 -j ACCEPT 在该行下面添加 -A INPUT -m state state NEW -m tcp -p tcp dport 80 -j ACCEPT :wq! #保存退出 systemctl restart iptables.service #最后重启防火墙使配置生效 systemctl enable iptables.service #设置防火墙开机启动7 7 开机自启动开机自启动 nginx7.17.1编写编写 shellshell 脚本脚本这里使用

11、的是编写 shell 脚本的方式来处理vi /etc/init.d/nginx (输入下面的代码)#!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but its not for everyone. # processname: nginx # pi

12、dfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/var/run/nginx.pid RETVAL=0 prog=“nginx“ # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/s

13、ysconfig/network # Check that networking is up. $NETWORKING = “no“ thenecho “nginx already running.“exit 1 fiecho -n $“Starting $prog: “daemon $nginxd -c $nginx_configRETVAL=$?echo $RETVAL = 0 ; stop)stop; reload)reload; restart)stopstart;status)status $progRETVAL=$?; *)echo $“Usage: $prog start|sto

14、p|restart|reload|status|help“exit 1 esac exit $RETVAL:wq 保存并退出7.27.2设置文件的访问权限设置文件的访问权限chmod a+x /etc/init.d/nginx (a+x = all user can execute 所有用户可执行)这样在控制台就很容易的操作 nginx 了:查看 Nginx 当前状态、启动 Nginx、停止 Nginx、 重启 Nginx如果修改了 nginx 的配置文件 nginx.conf,也可以使用上面的命令重新加载新的配置文件并 运行,可以将此命令加入到 rc.local 文件中,这样开机的时候 nginx 就默认启动了7.37.3加入到加入到 rc.localrc.local 文件中文件中vi /etc/rc.local加入一行 /etc/init.d/nginx start 保存并退出,下次重启会生效。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号