gpt4 book ai didi

performance - Varnish 和Nginx重定向8080-> 80

转载 作者:行者123 更新时间:2023-12-03 17:47:17 24 4
gpt4 key购买 nike

我正在尝试使用Varnish作为在Ubuntu 10.10上安装nginx的反向缓存代理,我已经在端口8080上设置了Varnish进行测试,并且nginx在端口80上正常运行。

我的nginx.conf:

user {user} {group};
worker_processes 16;

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

events {
worker_connections 1024;
multi_accept on;
}

http {
include /etc/nginx/mime.types;
client_max_body_size 4M;
client_body_buffer_size 128k;
access_log /var/log/nginx/access.log;

gzip on;
gzip_proxied any;
gzip_comp_level 2;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml$

sendfile on;
tcp_nopush off;

keepalive_timeout 30;
tcp_nodelay on;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

我网站的.conf文件:
server {
listen 80;
server_name www.mylesgray.com dev.mylesgray.com;

access_log /var/www/mylesgray.com/logs/access.log;
error_log /var/www/mylesgray.com/logs/error.log;

location / {
root /var/www/mylesgray.com/public;
index index index.php;
try_files $uri/ $uri index.php?q=$uri&$args;
port_in_redirect off;
}

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
access_log off;
expires 30d;
root /var/www/mylesgray.com/public;
}

location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/mylesgray.com/public/$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
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;
}

location ~ /.ht {
deny all;
}

location ~ /.git {
deny all;
}

# include /var/www/mylesgray.com/public/nginx.conf;
}

upstream backend {
server 127.0.0.1:9000;
}

我的Varnish conf:
backend default {
.host = "localhost";
.port = "80";
}

acl purge {
"localhost";
}

sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
return(lookup);
}

if (req.url ~ "^/$") {
unset req.http.cookie;
}
}

sub vcl_hit {
if (req.request == "PURGE") {
set obj.ttl = 0s;
error 200 "Purged.";
}
}

sub vcl_miss {
if (req.request == "PURGE") {
error 404 "Not in cache.";
}

if (!(req.url ~ "wp-(login|admin)")) {
unset req.http.cookie;
}

if (req.url ~ "^/[^?]+.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?$
unset req.http.cookie;
set req.url = regsub(req.url, "\?.$", "");
}

if (req.url ~ "^/$") {
unset req.http.cookie;
}
}

sub vcl_fetch {
if (req.url ~ "^/$") {
unset beresp.http.set-cookie;
}

if (!(req.url ~ "wp-(login|admin)")) {
unset beresp.http.set-cookie;
}
}

因此,当您在端口8080上访问我的站点时,所有这些内容都将重定向到普通的旧版本: http://www.mylesgray.com:8080它应该做的是(如果存在)如果我访问端口80,则我应该只获取nginx服务文件,并且如果我访问8080,我应该拥有Nginx + Varnish 服务文件。

我这样做是为了测试 Varnish 相对于普通Nginx的性能优势。

任何帮助,不胜感激!

最佳答案

我最好的猜测是某种 SEO 插件,它在想“哦,对端口 8080 的请求?那不应该,我会善意地重写到端口 80”:

$ curl -I "http://www.mylesgray.com:8080/"
HTTP/1.1 301 Moved Permanently
Server: nginx/0.7.65
Location: http://www.mylesgray.com/

您可能希望通过剥离端口号来规范主机 header :
set req.http.Host = regsub(req.http.Host, ":[0-9]+", "");

如果需要,请查看这些 configuration examples for Varnish 中的更多示例

关于performance - Varnish 和Nginx重定向8080-> 80,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9126655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com