[Nginx]使用Nginx进行HTTPS连接,并运行PHP代码[PHP]

使用nginx来运行PHP

作为备忘录,我将简略记录解决在HTTPS上无法运行PHP的问题的方法。

请将以下内容添加到nginx/conf.d/default.conf配置文件中。
可以随意更改根文件夹名称。

server {
        listen 443 ssl http2;
        server_name sample.com;

        if ($request_uri ~ ^.*/index.html$){
        rewrite ^(.*)/index.html$ $1/ permanent;
        }

        location / {
                root   /html;
                index  index.html index.htm index.php;
        }

        ssl_protocols TLSv1.2;
        ssl_ciphers EECDH+AESGCM:EECDH+AES;
        ssl_ecdh_curve prime256v1;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;

        ssl_certificate /etc/letsencrypt/live/sample.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/sample.com/privkey.pem;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /html;
        }

        location ~ \.php$ {
        root           /html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
        }
}

以上

Please note that “以上” is already in Chinese and does not require any paraphrasing. It can be translated as “the above” or “the foregoing.”