Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 配置问题:使用OpenResty和;LuaRESTY自动ssl_Php_Ssl_Nginx_Lets Encrypt_Openresty - Fatal编程技术网

Php 配置问题:使用OpenResty和;LuaRESTY自动ssl

Php 配置问题:使用OpenResty和;LuaRESTY自动ssl,php,ssl,nginx,lets-encrypt,openresty,Php,Ssl,Nginx,Lets Encrypt,Openresty,请原谅长篇大论-我真的非常感谢在以下方面的任何帮助 我正在尝试使用LetsEncrypt使用SSL设置多租户子域+自定义域: (有些将使用子域,有些将使用自定义域) 我在EC2实例上使用用户名为“Ubuntu”的Ubuntu操作系统 我从以下教程中学到: 我已成功完成以下工作: 已在服务器上安装基本版本 安装OpenResty(自带自己的Nginx和OpenSSL) 安装凸耳 安装lua resty自动ssl 为resty自动ssl创建目录 sudo mkdir /etc/resty-a

请原谅长篇大论-我真的非常感谢在以下方面的任何帮助

我正在尝试使用LetsEncrypt使用SSL设置多租户子域+自定义域:

(有些将使用子域,有些将使用自定义域)

我在EC2实例上使用用户名为“Ubuntu”的Ubuntu操作系统

我从以下教程中学到:

我已成功完成以下工作:

  • 已在服务器上安装基本版本
  • 安装OpenResty(自带自己的Nginx和OpenSSL)
  • 安装凸耳
  • 安装lua resty自动ssl
  • 为resty自动ssl创建目录

    sudo mkdir /etc/resty-auto-ssl
    sudo chown -R ubuntu /etc/resty-auto-ssl
    sudo chown -R www-data /etc/resty-auto-ssl
    chmod -R 777 /etc/resty-auto-ssl/
    
  • 已创建回退自签名证书,该证书将在3600天后过期

这是我的初学者配置文件(/usr/local/openresty/nginx/conf/nginx.conf)

(我将进一步完善它,以满足我的重定向和安全需求)

我面临多个问题,如:

  • 无法在nginx配置中提及用户-没有它也可以工作

    • 试图在配置文件的第1行中提到用户会导致错误
    • 所以我把它评论了出来,并试着随便说说
  • 失败,但已创建证书

    • 在我的日志中不断出现以下错误:
      
      让我们加密。lua:40:issue\u cert():auto-ssl:determinated失败:env HOOK_SECRET=XXXX HOOK_SERVER_PORT=8999/usr/local/openresty/luajit/bin/resty auto-ssl/determinated--cron--accept terms--no lock--domain myapp.com--challenge http-01--config/etc resty auto ssl/letsencrypt/config--HOOK/usr/local openresty/luajit/bin/resty auto ssl/letsencrypt挂钩状态:256 out:#信息:使用主配置文件/etc/resty auto ssl/letsencrypt/config
    • 但它仍在继续&确实创建了一个证书,在该证书之后,它会给出随机数生成器错误
    • 有时,如果我删除
      /etc/resty auto ssl
      中的所有内容,它不会给我此类错误
  • 找不到OpenSSL随机数生成器

    • 我的日志中不断出现以下错误:
      
      无法将./.rnd加载到RNG中
      随机数生成器:随机数加载文件:无法打开文件:../crypto/RAND/randfile.c:98:Filename=../.rnd
      curl:(22)请求的URL返回错误:500内部服务器错误
  • OpenResty提供的nginx上的PHP-FPM

    • 我已经正确安装了php fpm,并在使用nginx standalone时对其进行了测试
    • 但是,现在我正在使用openresty提供的nginx,它似乎不起作用
    • 错误(使用:nginx-t命令测试配置时显示):
      
      “/usr/local/openresty/nginx/conf/snippets/fastcgi php.conf”失败(2:没有这样的文件或目录)
  • 无法创建证书

    • 有时,该错误后会出现上述第2点中的错误:
    auto-ssl:无法获取myapp.com的证书-使用回退-无法获取或颁发证书,上下文:ssl\u certificate\u by_lua*,客户端:123.201.226.209,服务器:0.0.0.0:443

    set\u response\u cert():自动ssl:无法为xxxx.myapp.com设置ocsp绑定-仍在继续-无法获取ocsp响应:ocsp响应程序查询失败(http://ocsp.int-x3.letsencrypt.org):未定义解析程序来解析“ocsp.int-x3.letsencrypt.org”,上下文:ssl\u certificate\u by_lua*,客户端:123.201.226.209,服务器:0.0.0.0:443

    connect()到unix:/run/php/php7.4-fpm.sock在连接到上游时失败(13:权限被拒绝),客户端:123.201.226.209,服务器:,请求:“GET/HTTP/1.1”,上游:fastcgi://unix:/run/php/php7.4-fpm.sock:,主机:“xxxx.myapp.com”

  • 尝试访问customer1.com时,记录指向myapp.com服务器IP的用户

    “创建新订单时出错::无法为\“X.X.X.X\”颁发证书:ACME服务器无法为IP地址颁发证书”

    ssl\u证书。lua:281:auto-ssl:无法确定请求的域(不支持SNI?)-使用回退,上下文:ssl\u证书\u by\u lua*,客户端:45.148.10.72,服务器:0.0.0.0:443

    • 。。。其中x.x.x.x是从浏览器中打开的customer1.com的记录
  • 我有以下困惑:

  • 我应该为myapp.com获得一个正确的(付费)通配符正ssl证书吗?(并将其用作后备)

    • 这涵盖了我的所有子域,我不必处理letsencrypt对子域的限制
    • 这样,我只需要对自定义域(如customer1.com)使用lets加密
  • 我不确定是否正确设置了我的用户和权限-任何指针都会有所帮助

  • 我希望我的最终nginx配置能够满足以下需求

    • 重定向到->
    • 重定向到->
    • 重定向到->
    • 然后在我的acutal ssl服务器块上,写入自动生成ssl的所有逻辑

  • 回答所有这些问题有点困难,所以我将尝试回答第5部分和第6部分。我已经在prod环境中自己设置了OpenRESTY,请参阅

  • 我遇到了OCSP装订问题。我发现通过将以下内容添加到我的NGINX配置中解决了此问题:
  • 关于问题6,我建议customer1.com应该是myapp.com的CNAME

    我还建议使用openresty docker映像作为基础,或者至少在EC2实例中使用docker映像的反向工程版本。这是我的dockerfile:

    FROM openresty/openresty:latest-xenial
    
    RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-auto-ssl
    RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-http
    RUN apt-get update
    RUN apt-get install -y dnsutils
    
    RUN openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj '/CN=sni-support-required-for-valid-ssl' -keyout /etc/ssl/resty-auto-ssl-fallback.key -out /etc/ssl/resty-auto-ssl-fallback.crt
    
    ADD nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
    

    希望这会有所帮助。

    回答所有这些问题有点困难,所以我将尝试回答第5部分和第6部分。我已经在prod环境中自己设置了OpenRESTY,请参阅

  • 我遇到了OCSP装订问题。我发现通过将以下内容添加到我的NGINX配置中解决了此问题:
  • 关于探索
    #user nginx;
    
    error_log  /usr/local/openresty/nginx/logs/error.log warn;
    
    events {
        worker_connections 1024;
    }
    
    http {
    
      lua_shared_dict auto_ssl 1m;
      lua_shared_dict auto_ssl_settings 64k;
    
      init_by_lua_block {
    
        auto_ssl = (require "resty.auto-ssl").new()
        auto_ssl:set("allow_domain", function(domain)
          return true
        end)
        auto_ssl:set("dir", "/etc/resty-auto-ssl")
        auto_ssl:init()
    
      }
    
      init_worker_by_lua_block {
        auto_ssl:init_worker()
      }
    
     # access_log /usr/local/openresty/nginx/logs/access.log main;
    
      server {
    
          listen 443 ssl;
    
          ssl_certificate_by_lua_block {
            auto_ssl:ssl_certificate()
          }
    
          ssl_certificate /etc/ssl/resty-auto-ssl-fallback.crt;
          ssl_certificate_key /etc/ssl/resty-auto-ssl-fallback.key;
    
          root /var/www/myapp.com/public;
          index index.php index.html index.htm;
    
          location / {
    
            try_files $uri $uri/ /index.php?$query_string; 
    
          }
    
    #     location ~ \.php$ {
    #       include snippets/fastcgi-php.conf;
    #       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    #       fastcgi_read_timeout 600;
    #     }
    
          location ~ /\.ht {
            deny all;
          }
    
      }
    
      server {
    
        listen 80;
        server_name *.myapp.com myapp.com;
    
        location /.well-known/acme-challenge/ {
            content_by_lua_block {
              auto_ssl:challenge_server()
            }
        }
    
        location / {
          return 301 https://myapp.com$request_uri;
        }
    
      }
    
      server {
    
        listen 8999;
    
        location / {
            content_by_lua_block {
              auto_ssl:hook_server()
            }
        }
    
      }
    
    }
    
    # A DNS resolver must be defined for OSCP stapling to function.
    resolver 172.20.0.10 ipv6=off;
    
    FROM openresty/openresty:latest-xenial
    
    RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-auto-ssl
    RUN /usr/local/openresty/luajit/bin/luarocks install lua-resty-http
    RUN apt-get update
    RUN apt-get install -y dnsutils
    
    RUN openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -subj '/CN=sni-support-required-for-valid-ssl' -keyout /etc/ssl/resty-auto-ssl-fallback.key -out /etc/ssl/resty-auto-ssl-fallback.crt
    
    ADD nginx.conf /usr/local/openresty/nginx/conf/nginx.conf