• centos6安装nginx


    1、获取官方的仓库地址

    我们需要先访问nginx的官方网站,获取官方的仓库地址https://nginx.org/en/linux_packages.html#stable

    新建/etc/yum.repos.d/nginx.repo 文件

    内容为:

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

     

    2、安装好仓库后可以直接使用yum安装nginx

    yum install -y nginx

     

    3、启动nginx

    service nginx start

    4、查看

    netstat -tunlp|grep 80

    就可以看到nginx已经启动了80端口的监听。

    并且通过浏览器直接访问服务器的ip地址,能看到已经出现了nginx的欢迎页面

    5、设置nginx为开机启动

    chkconfig nginx on

     

    6、配置nginx使其支持php程序

    。创建web目录和文件

    我们假设web目录为/var/www,创建并进入这个目录。

    mkdir /var/www

    cd /var/www

    我们新建两个文件,一个html文件,一个php文件,稍后会看到效果。

    a.html的内容为:

    <h1>Hello World</h1>

    b.php的内容为:

    <?php

    phpinfo();

    ?>

     

    。变更nginx配置

    vim打开nginx第一个站点的配置文件vim /etc/nginx/conf.d/default.conf

    将第9行的root变更为我们指定的目录。

    修改

    location / {

            root   /usr/share/nginx/html;

            index  index.html index.htm;

       }

    变更为

        location / {

            root   /var/www;

            index  index.html index.htm;

       }

     将30-36行的注释去掉,使其支持php文件,同时还需要修改root和fastcgi_param选项指定我们的工作目录。

    修改

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    #location ~ .php$ {

    #    root           html;

    #    fastcgi_pass   127.0.0.1:9000;

    #    fastcgi_index  index.php;

    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

    #    include        fastcgi_params;

    #}

     

    变更为

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

       #

        location ~ .php$ {

            root           /var/www;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;

            include        fastcgi_params;

        }

    保存后,执行service nginx reload重新载入nginx配置。

    此时,我们可以通过浏览器直接访问我们刚才建立的文件了。

  • 相关阅读:
    printf里的=、++
    线程也疯狂-----异步编程
    自己搭建node服务器环境(请求静态资源、get请求、post请求)
    React学习
    2020.10-2021-01总结
    接圈的作用和缺点
    CWnd,HWND; CDC,HDC
    Python通过requests模块处理form-data请求格式
    element-ui resetFields 无效的问题
    用python 将数字每三组分割
  • 原文地址:https://www.cnblogs.com/sky-cheng/p/10564798.html
Copyright © 2020-2023  润新知