重定向 – Nginx Php-fpm的延迟问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了重定向 – Nginx Php-fpm的延迟问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2146字,纯文字阅读大概需要4分钟。
内容图文
我有一个PHP应用程序,曾经在Apache上运行我刚刚切换到nginx.
我的php应用程序有一个php路由器,所以对于某些页面,流程就像是:
>您想要访问www.example.com
>由于您已登录,因此php会将重定向301发送到/ user / home.
使用Apache,php重定向在几百毫秒内完成,而使用nginx需要~2秒!
php重定向funtcion:
public function redirect($url, $code = 301)
{
if($code) {
$codeHeader = false;
switch ($code) {
case 301:
$codeHeader = "HTTP/1.1 301 Moved Permanently";
break;
}
if($codeHeader){
header($codeHeader);
}
}
header("Location: $url");
exit;
}
我的nginx.conf:
user www-data;
worker_processes 8;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
reset_timedout_connection on;
client_body_timeout 10;
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log main buffer=16k;
error_log /var/log/nginx/error.log crit;
gzip on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]\.";
application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我的应用程序vhost:
server {
listen 80;
root /srv/www/example;
server_name www.example.com;
access_log /var/log/nginx/access.example.log;
error_log /var/log/nginx/error.example.log;
index /index.php;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \..*/.*\.php${
return 403;
}
# Block hidden files
location ~ (^|/)\. {
return 403;
}
location ~ \.(php|phtml)${
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass_header X-Real-IP;
fastcgi_pass_header X-Forwarded-For;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/error.example.log";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
谁知道滞后来自哪里?
内容总结
以上是互联网集市为您收集整理的重定向 – Nginx Php-fpm的延迟问题全部内容,希望文章能够帮你解决重定向 – Nginx Php-fpm的延迟问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。