zoukankan      html  css  js  c++  java
  • centos7下安装ngnix1.8.1

    参考 http://www.linuxidc.com/Linux/2016-09/134907.htm

    安装依赖

    openssl zlib pcre gcc

    下载安装包

    [root@localhost src]# wget http://nginx.org/download/nginx-1.8.1.tar.gz
    解压缩安装包

    [root@localhost src]# tar -zxvf nginx-1.8.1.tar.gz -C /usr/local

    安装 gcc

    安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装

    [root@localhost nginx-1.8.1]# yum -y install gcc-c++

    安装 pcre  pcre-devel

    PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:

    [root@localhost nginx-1.8.1]# yum -y install pcre-devel

    安装 zlib-devel

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

    [root@localhost nginx-1.8.1]# yum -y install zlib-devel

    OpenSSL 安装

    OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
    nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。

    [root@localhost nginx-1.8.1]# yum install -y openssl openssl-devel

    安装nginx

    [root@localhost nginx-1.8.1]# ./configure    #默认安装到/usr/local/nginx目录下

    [root@localhost nginx-1.8.1]# make    #编译

    [root@localhost nginx-1.8.1]# make install    #安装

    启动ngnix

    [root@localhost local]# cd /usr/local/nginx/sbin
    [root@localhost sbin]# ./nginx  #启动命令注意输入的 点和斜杠,如果直接输入 nginx会提示  "bash: nginx: 未找到命令..."
    查看nginx进程

    [root@localhost sbin]# ps -ef|grep nginx
    root      5455     1  0 06:24 ?        00:00:00 nginx: master process ./nginx
    nobody    5456  5455  0 06:24 ?        00:00:00 nginx: worker process
    root      5500  4179  0 06:26 pts/1    00:00:00 grep --color=auto nginx

    从容停止-杀死进程

    kill -QUIT 5455

    快速停止-杀死进程

    kill -TERM 5455

    强制停止-杀死进程

    kill -9 5455

    在浏览器访问 http://localhost

    Welcome to nginx!

    If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

    For online documentation and support please refer to nginx.org.
    Commercial support is available at nginx.com.

    Thank you for using nginx.

    nginx目录下内容

    [root@localhost nginx]# ll
    总用量 4
    drwx------. 2 nobody root    6 3月  27 23:02 client_body_temp
    drwxr-xr-x. 2 root   root 4096 3月  27 23:04 conf
    drwx------. 2 nobody root    6 3月  27 23:02 fastcgi_temp
    drwxr-xr-x. 2 root   root   40 3月  27 22:57 html
    drwxr-xr-x. 2 root   root   58 3月  28 06:24 logs
    drwx------. 2 nobody root    6 3月  27 23:02 proxy_temp
    drwxr-xr-x. 2 root   root   19 3月  27 22:57 sbin
    drwx------. 2 nobody root    6 3月  27 23:02 scgi_temp
    drwx------. 2 nobody root    6 3月  27 23:02 uwsgi_temp
    [root@localhost nginx]#

    nginx常用命令

    nginx -t:检查配置文件是否正确。这个命令可以检查nginx.conf配置文件其格式、语法是否正确。如果配置文件存在错误,则会出现相应提示;如果nginx.conf文件正确,也会出现相应的成功提示。

    [root@localhost sbin]# ./nginx -t
    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

    nginx -s reload:重加载/重启nginx——以新的nginx.conf配置文件中的定义。

    nginx -s stop:停止nginx。必须有-s参数

  • 相关阅读:
    [leetcode]43. Multiply Strings
    [leetcode]387. First Unique Character in a String
    Penetration Test
    Penetration Test
    Penetration Test
    Penetration Test
    Penetration Test
    Penetration Test
    Penetration Test
    Penetration Test
  • 原文地址:https://www.cnblogs.com/xhkj/p/6629072.html
Copyright © 2011-2022 走看看