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 协议,并提供丰富的应用程序供测试或其它目的使用.html

  • nginx 不只支持 http 协议,还支持 https(即在 ssl 协议上传输 http),因此须要在 linux安装 openssl 库。
    yum install -y openssl openssl-devellinux

  • 如今开始正式安装:
  • 1.把Nginx的源码压缩包上传到Linux系统.上传的时候,在CRT中,右键选项卡,选择"链接到SETP会话", 将文件直接拖到窗口便可,
  • 2, 解压缩文件:
  • tar -zxvf nginx-1.8.0.tar.gz
  • 3, 进行configure .执行configure进行编译源码
  • 直接在[root@localhost nginx-1.8.0] 编译这段代码:nginx

    ./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/scgic++

  • 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 是端口,算法

安装完毕!

相关文章
相关标签/搜索