免责声明:我发布了这个在Stackoverflow以及我认为它可能有适合更好的。 如果有人想在那里回答的话,下面的问题链接如下。
–
我有以下几点:
domain.com – 很多不需要SSL的URL(我想用varnish来caching所有这些)domain.com/shop – 所有的URL都应该使用SSL(不需要清漆,我想在端口上听443)
我基本上是寻找configuration服务器来caching所有不需要SSL的uris的最佳方法,因为这必须在端口443上运行。所有端口8080请求都将变为Varnish并正常工作。 另外我想确保和非ssl请求被发送到domain.com(包括www请求)。 我之前做过这个,但由于某种原因,等式中的SSL使事情变得复杂。
我的configuration如下:
`server { listen 8080; server_name domain.com; root /var/www/domain.com/public_html; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } location ~ \.php$ { fastcgi_buffers 8 256k; fastcgi_buffer_size 128k; fastcgi_intercept_errors on; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/dev/shm/php-fpm-www.sock; # Tried using to shut off http on all non SSL needed urls. fastcgi_param HTTPS off; } } server { listen 443 ssl; server_name domain.com; ssl_certificate /etc/nginx/keys/www.domain.com.chained.crt; ssl_certificate_key /etc/nginx/keys/domain.com.key; access_log /var/www/domain.com/logs/access.log ; error_log /var/www/domain.com/logs/error.log ; root /var/www/domain.com/public_html; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } location ~ \.php$ { fastcgi_buffers 8 256k; fastcgi_buffer_size 128k; fastcgi_intercept_errors on; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/dev/shm/php-fpm-www.sock; #https will not work without this. fastcgi_param HTTPS on; } }
尝试端口分配:
Varnish:80 => NginX:8080 NginX:443
这样,你可以像上面的caching层一样通过清漆来减less对NginX的请求数量。
你的应用程序应该通过头文件来控制如何caching内容,默认情况下它应该可以正常工作 – 只要有效date头文件中提到,dynamic文件就会传递给NginX,而静态文件则从caching中提供。
这是我们可以做的。 我使用这种模式为“admin”页面启用SSH(在WordPress中)。 希望它适用于你的情况。
服务器{
听8080;
server_name domainname.com;
root /path/to/domainname.com/installation;
index index.php;
位置〜\ .php $ {
#请求/购物通过HTTPS去
位置〜/ shop {
返回301 https:// $ host $ request_uri;
}
#处理非网店PHP请求
try_files $ uri = 404;
包括fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
}
位置 / {
try_files $ uri $ uri / /index.php;
}
}
服务器{
听443 ssl;
server_name domainname.com;
ssl_certificate xyz.crt;
ssl_certificate_key xyz.key;
root /path/to/domainname.com/installation;
index index.php;
#只处理购物请求
位置〜/ shop {
位置〜\ .php $ {
try_files $ uri = 404;
包括fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
fastcgi_param HTTPS;
}
}
#将其他一切redirect到端口80(清漆)
位置 / {
返回301 http:// $ host $ request_uri;
}
}