Nginx的安装和部署

  • 在做项目的时候,我们需要一个专门的服务器来接收并保存图片,这样就需要在图片服务器上安装一个http服务器, 可以使用: Tomcat, Apache, Nginx, 这里我们介绍一下Nginx在Linux上的安装和部署.

  • Nginx一般推荐安装到Linux系统, 因为Nginx是用C语言开发的,所以需要安装c语言的编译环境gcc.

  • 1,进入 http://nginx.org/en/download.html 下载 nginx 版本:

  • nginx-1.8.0.tar.gz

  • 2,安装gcc环境:

  • yum install gcc-c++

  • 3,安装pcre库:

  • PCRE(Perl Compatible Regular Expressions)是一个 Perl 库,包括 perl 兼容的正则表达式库。 nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在Linux上安装pcre库.

  • yum install -y pcre pcre-devel

  • 注: pcre-devel 是使用 pcre 开发的一个二次开发库。 nginx 也需要此库

  • 安装zlib

  • zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip,所以需要在 linux 上安装 zlib 库。
    yum install -y zlib zlib-devel

  • 安装openssl

  • OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用.

  • nginx 不仅支持 http 协议,还支持 https(即在 ssl 协议上传输 http),所以需要在 linux安装 openssl 库。
    yum install -y openssl openssl-devel

  • 现在开始正式安装:

  • 1.把Nginx的源码压缩包上传到Linux系统.上传的时候,在CRT中,右键选项卡,选择"连接到SETP会话", 将文件直接拖到窗口即可,

  • 2, 解压缩文件:

  • tar -zxvf nginx-1.8.0.tar.gz

  • 3, 进行configure .执行configure进行编译源码

  • 直接在[root@localhost nginx-1.8.0] 编译这段代码:

./configure
--prefix=/usr/local/nginx
--pid-path=/var/run/nginx/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/fastcgi
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi
--http-scgi-temp-path=/var/temp/nginx/scgi

  • 4,然后执行make

  • 5,执行,make install

  • 6,这时会发现/usr/local 目录下会多一个nginx

  • 7,nginx的启动:

  • 启动:进入/user/local/nginx 的 sbin 目录, ./nginx 就可以启动。

  • 8,查看进程:

  • [root@localhost sbin]# ps aux|grep nginx

  • 9.然后通过IP访问.

  • 10,如果访问不到,要查看防火墙是否关闭:

  • service iptables restart

  • 11.关闭nginx:

  • 可以使用 kill 命令,但是不推荐使用:kill 4746(这个是root后边的值)

  • 快速停止: ./nginx -s stop
    cd /usr/local/nginx/sbin
    ./nginx -s stop
    此方式相当于先查出 nginx 进程 id 再使用 kill 命令强制杀掉进程

  • 完整停止:

  • 完整停止(建议使用): ./nginx -s quit
    cd /usr/local/nginx/sbin
    ./nginx -s quit
    此方式停止步骤是待 nginx 进程处理任务完毕进行停止

  • 12.刷新配置:

  • a. 重新加载配置文件
    当 nginx 的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload
    不用先停止 nginx 再启动 nginx 即可将配置信息在 nginx 中生效,如下:
    ./nginx -s reload

  • 13, 先停止再启动(建议使用):
    对 nginx 进行重启相当于先停止 nginx 再启动 nginx, 即先执行停止命令再执行启动命
    令。如下:
    ./nginx -s quit
    ./nginx

  • 14 .nginx的配置:

  • 在/usr/local/nginx/conf 目录下 nginx.conf 文件是 nginx 的配置文件。

  • server是一个虚拟机,80 是端口,

安装完毕!

posted @ 2017-12-28 18:34  煮酒问寒秋  阅读(163)  评论(0编辑  收藏  举报