FastCGI发送到stderr nginx,FastCGI发送到stderr:" PHP消息:PHP注意:未定义索引:HTTP_REFERER

时间:2018-02-21 21:56:57

标签: php nginx fastcgi

尝试在nginx + fpm中配置旧的php网站,我看到以下错误

nginx配置如下

server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;

    root /var/www/html/example/public_html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name example.com www.example.com ;

    server_name server_IP_address;

    ssl_certificate /etc/ssl/example/example-chain.cer  ;
    ssl_certificate_key /etc/ssl/example/example.key;
    #ssl_dhparam /etc/ssl/certs/dhparam.pem;

        access_log /var/log/nginx/example_ssl_access;
        error_log /var/log/nginx/example_ssl_error error;

        location / {

        #try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$query_string;

        }


        location ~ \.php$ {
            fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

问题显示的代码是

         $path =  parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY );

echo $ path

通过网络我看到以下

Notice: Undefined index: HTTP_REFERER in /var/www/html/example/public_html/newsroom/news.php on line 305

我也打印了服务器变量并显示:

Array
(
    [USER] => www-data
    [HOME] => /var/www
    [HTTP_CACHE_CONTROL] => max-age=0
    [HTTP_UPGRADE_INSECURE_REQUESTS] => 1
    [HTTP_ACCEPT_ENCODING] => gzip, deflate, br
    [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5
    [HTTP_HOST] => example.com
    [REDIRECT_STATUS] => 200
    [SERVER_NAME] => example.com
    [SERVER_PORT] => 443
    [SERVER_ADDR] => 1.1.1.1
    [REMOTE_PORT] => 55388
    [REMOTE_ADDR] => 2.2.2.2
    [SERVER_SOFTWARE] => nginx/1.12.1
    [GATEWAY_INTERFACE] => CGI/1.1
    [HTTPS] => on
    [REQUEST_SCHEME] => https
    [SERVER_PROTOCOL] => HTTP/2.0
    [DOCUMENT_ROOT] => /var/www/html/example/public_html
    [DOCUMENT_URI] => /newsroom/news.php
    [REQUEST_URI] => /newsroom/news.php?news=289
    [SCRIPT_NAME] => /newsroom/news.php
    [CONTENT_LENGTH] => 
    [CONTENT_TYPE] => 
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => news=289
    [SCRIPT_FILENAME] => /var/www/html/example/public_html/newsroom/news.php
    [PATH_INFO] => 
    [FCGI_ROLE] => RESPONDER
    [PHP_SELF] => /newsroom/news.php
    [REQUEST_TIME_FLOAT] => 1519249027.5617
    [REQUEST_TIME] => 1519249027
)

任何想法或建议如何解决此错误?

提前谢谢

0 个答案:

没有答案