zoukankan      html  css  js  c++  java
  • centos8上配置openresty/nginx可访问php

    一,创建一个测试站的目录

    [root@yjweb data]# mkdir dev
    [root@yjweb data]# cd dev
    [root@yjweb dev]# mkdir think_www
    [root@yjweb dev]# cd think_www/
    [root@yjweb think_www]# mkdir html
    [root@yjweb think_www]# cd html
    [root@yjweb html]# vi phpinfo.php

    说明:phpinfo.php用来测试

      内容:

    <?php
    phpinfo();
    ?>

    说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

             对应的源码可以访问这里获取: https://github.com/liuhongdi/

     说明:作者:刘宏缔 邮箱: 371125307@qq.com

    二,对nginx的配置

    1,创建日志目录

    [root@yjweb ~]# mkdir /data/logs/nginxlogs
    [root@yjweb ~]# chmod 777 /data/logs/nginxlogs

    3,创建各server所用的配置文件所在的目录

    [root@yjweb conf]# pwd
    /usr/local/openresty/nginx/conf
    [root@yjweb conf]# mkdir conf.d

    4,修改nginx的配置文件

    [root@yjweb conf]# vi nginx.conf

    配置内容:

    user  nginx;

    //工作进程数,一般可以设置为cpu数量的2倍(cpu支持超线程,所以乘2)

    worker_processes  8;

    //单个工作进程可以建立连接的数量,默认1024,可以调高一些

    说明;这个值不能超过系统中单进程可以同时打开的文件数,

    可以用这个命令查询:

    [root@yjweb nginxlogs]# ulimit -n
    65535
    worker_connections  2048;

    //指定post可上传内容的大小,建议和后端业务daemon的配置一致

    //例如: php的post_max_size 

    client_max_body_size 128m;
    error_log  /data/logs/nginxlogs/error.log;

    //把各server的conf文件include进来

    include /usr/local/openresty/nginx/conf/conf.d/*.conf;

    5,在conf.d目录中增加一个server

    [root@yjweb conf.d]# vi www.conf

    内容为:

    server {
    
        listen       80;
        server_name  www.demodomain.net;
        root         /data/web/think_www/html;
        index   index.php index.html index.shtml  index.htm;
        access_log      /data/logs/nginxlogs/www.access_log;
        error_log       /data/logs/nginxlogs/www.error_log;
    
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
    
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_buffer_size 32k;
            fastcgi_buffers 10240 32k;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    三,修改完成后重启openresty

    [root@yjweb conf]# systemctl stop openresty
    [root@yjweb conf]# systemctl start openresty

    四,测试效果

    从浏览器访问:

    http://www.demodomain.net/phpinfo.php

    五,查看日志目录是否有日志文件写入?

    [root@yjweb crontab]# ll /data/logs/nginxlogs
    total 12
    -rw-r--r-- 1 nginx root 350 Mar  6 15:40 error.log
    -rw-r--r-- 1 nginx root 263 Mar  6 15:31 www.access_log
    -rw-r--r-- 1 nginx root 207 Mar  6 15:31 www.error_log

    六,查看本地centos的版本

    [webop@yjweb ~]$ cat /etc/redhat-release
    CentOS Linux release 8.0.1905 (Core) 

    七,查看本地openresty的版本

    [webop@yjweb ~]$ /usr/local/openresty/bin/openresty -V
    nginx version: openresty/1.15.8.2
    built by gcc 8.2.1 20180905 (Red Hat 8.2.1-3) (GCC)
    built with OpenSSL 1.1.0k  28 May 2019
    TLS SNI support enabled
  • 相关阅读:
    Ubuntu下手动安装vscode
    VMware Tools安装后设置自动挂载解决共享文件夹无法显示的问题
    VMware Tools安装方法及共享文件夹设置方法
    JavaScript原始类型转换和进制转换
    Javascript的数据类型(原始类型和引用类型)
    设计模式(六)观察者模式
    设计模式(五)之适配器模式
    设计模式(四)注册模式 解决:解决全局共享和交换对象
    设计模式(三)单例模式
    设计模式(二)之策略模式
  • 原文地址:https://www.cnblogs.com/architectforest/p/12433732.html
Copyright © 2011-2022 走看看