简体   繁体   English

$ _SERVER ['REMOTE_ADDR']不适用于php-fpm和nginx

[英]$_SERVER['REMOTE_ADDR'] doesn't work with php-fpm and nginx

I don't know why with nginx this variable $_SERVER['REMOTE_ADDR'] doesn't echo an IP. 我不知道为什么使用nginx这个变量$ _SERVER ['REMOTE_ADDR']不会回显IP。 On every other web server it works as it should. 在其他每个Web服务器上,它都可以正常工作。

Any suggestions? 有什么建议么?

I suspect it has something to do with the interface between nginx (the webserver) and fastcgi, which is the API in which PHP is running. 我怀疑它与nginx(webserver)和fastcgi之间的接口有关,而fastcgi是运行PHP的API。

According to your info provided, the Server API is: FPM/FastCGI 根据您提供的信息,Server API为: FPM/FastCGI

I suggest you take a hard look at the details of how PHP is installed with nginx (you have not provided any). 我建议你仔细看看如何用nginx安装PHP的细节(你还没有提供)。

If you do not require the performance of nginx, then you may find a pragmatic solution is to just use apache. 如果你不需要nginx的性能,那么你可能会发现一个实用的解决方案就是使用apache。 I use nginx as a reverse proxy in front of apache, but that introduces some additional issues with getting the REMOTE_ADDR passed to PHP (notably, mod_rpaf). 我在apache之前使用nginx作为反向代理,但这引入了一些额外的问题,即将REMOTE_ADDR传递给PHP(特别是mod_rpaf)。

Good luck! 祝好运!

@Michael, here is a project I maintain which provides the proper fastcgi parameters for interfacing Nginx with FPM. @Michael,这是我维护的一个项目,它提供了适当的fastcgi参数,用于连接Nginx和FPM。 Hope it helps. 希望能帮助到你。

fastcgi_params on Github github上的fastcgi_params

These are from the conf file from nginx 这些来自nginx的conf文件

user http; 用户http; worker_processes 1; worker_processes 1;

error_log /var/log/nginx/error.log; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; pid /var/run/nginx.pid;

events { worker_connections 1024; events {worker_connections 1024; # multi_accept on; #ulti_accept on; } }

http { include mime.types; http {include mime.types; default_type application/octet-stream; default_type application / octet-stream; access_log /var/log/nginx/access.log; access_log /var/log/nginx/access.log;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;
tcp_nodelay        on;

gzip  on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

server { listen 80; 服务器{listen 80; server_name www.fireangel.ro fireangel.ro; server_name www.fireangel.ro fireangel.ro; access_log /var/log/nginx/localhost.access.log; access_log /var/log/nginx/localhost.access.log;

Default location 默认位置

location / {
    root    /var/www/html/fireangel.ro/public_html;
    index  index.php;
}

Images and static content is treated different 图像和静态内容的处理方式不同

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
  access_log        off;
  expires           30d;
  root  /var/www/html/fireangel.ro/public_html;

}

Parse all .php file in the /srv/http directory 解析/ srv / http目录中的所有.php文件

location ~ .php$ {
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass   backend;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME   /var/www/html/fireangel.ro/public_html$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_intercept_errors        on;
    fastcgi_ignore_client_abort     off;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
}

Disable viewing .htaccess & .htpassword 禁用查看.htaccess和.htpassword

location ~ /\.ht {
    deny  all;
}

} upstream backend { server 127.0.0.1:9000; 上游后端{server 127.0.0.1:9000; } }

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM