zoukankan      html  css  js  c++  java
  • CentOS7.0使用Yum安装Nginx

    安装Nginx

    yum install nginx

    正常情况下必定是:

    已加载插件:fastestmirror, langpacks
    base                                                            | 3.6 kB  00:00:00     
    docker-main                                                     | 2.9 kB  00:00:00     
    extras                                                          | 3.4 kB  00:00:00     
    updates                                                         | 3.4 kB  00:00:00     
    (1/2): extras/7/x86_64/primary_db                               | 122 kB  00:00:00     
    (2/2): updates/7/x86_64/primary_db                              | 2.9 MB  00:00:28     
    Loading mirror speeds from cached hostfile
     * base: mirrors.163.com
     * extras: mirrors.163.com
     * updates: mirrors.163.com
    没有可用软件包 nginx。
    错误:无须任何处理

    遂百度查找,CentOS7系统库中默认是没有Nginx的rpm包的,所以我们自己需要先更新下rpm依赖库。。。

    #rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

    a、先创建一个yum的一个repository文件:/etc/yum.repos.d/nginx.repo;

    b、然后将下面配置粘贴进文件后保存。

    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=0
    enabled=1

    接下来基本上就顺了:

    (1)安装Nginx
    
    #yum install nginx
    
    (2)启动Nginx
    
    #service nginx start
    #systemctl start nginx.service

    访问一下:

    curl http://127.0.0.1
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
        body {
            width: 35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
     
    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
     
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>

    本机访问虚拟机ip:

    ps:如果访问失败

    1、可能是防火墙的问题:

    关闭防火墙   service iptables stop

    2、也可能是80端口没有打开:

     /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT  

  • 相关阅读:
    ISP基础(01):ISP模块列表
    Linux 开发(02):打印特殊含义转义符
    note template
    apply、call、bind的区别
    Fiddle 抓包工具
    post和get的使用场景和区别
    闭包
    原型链
    node.js
    CSS垂直居中
  • 原文地址:https://www.cnblogs.com/lamp01/p/7390179.html
Copyright © 2011-2022 走看看