zoukankan      html  css  js  c++  java
  • Mac 使用 brew 安装 nginx 配置 php

    Mac 使用 brew 安装 nginx 配置 php

    一.安装

    查找 brew search nginx 可用版本
    使用 brew install nginx 安装nginx

    二.安装完成后brew会输出关于nginx的配置信息

    根目录
    #Docroot is: /usr/local/var/www  
    配置文件和启动端口
    #The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
    #nginx can run without sudo.
    #nginx will load all files in /usr/local/etc/nginx/servers/. 
    使用brew方式启动nginx
    #To have launchd start nginx now and restart at login:
    #  brew services start nginx 
    使用更简便的方式启动nginx
    #Or, if you don't want/need a background service you can just run:
    #  nginx 
    

    三.访问 localhost:8080

    Nginx 默认 8080 端口,这时已经可以访问了:
    localhost:8080
    会有一个默认欢迎界面,到此如果打开成功,那么Nginx安装成功了。
    

    四.修改Nginx配置

    1. 打开 nginx.config 文件 
    vim /usr/local/etc/nginx/nginx.conf 
    
    2. 找到 server 的 location 配置,给 index 加一个 index.php 
    location / {
      root  html;
      index index.html index.htm index.php;
    }
    3. 并打开 server 下被注释的 location ~.php$(即删除代码前面的 ‘#'),如下:
     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;
        }     
    4. 并修改 fastcgi_param 参数
     fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 
     改为  
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    
    5. 创建 index.php在 /usr/local/var/www 目录下,删除 index.html,创建 index.php,输入
     <?php phpinfo(); ?> 
    
    6. 启动Nginx和PHP
     sudo nginx 
     sudo php-fpm 
    然后访问 localhost:8080,看到 php 配置信息,就说明 ok 了
    
    7. 其他相关命令 
    重载配置文件 
    sudo nginx -s reload 
    停止 nginx 服务器 
    sudo nginx -s stop 
    
    
  • 相关阅读:
    使用RedisTemplate的操作类访问Redis(转载)
    Redis集群方案(来自网络)
    Scale-up and Scale-out(转载)
    数据结构和算法分析 优先队列
    数据结构和算法分析 排序
    linux下的常用命令
    Java HashMap的工作原理(转载)
    二叉查找树(转载)
    Redis实现之对象(三)
    Redis实现之对象(二)
  • 原文地址:https://www.cnblogs.com/ikai/p/11652604.html
Copyright © 2011-2022 走看看