Enable Browser-Caching for lighttpd/thin - ruby-on-rails

I have the problem that Googles “Page Speed” says that I should enable browser caching.
I am usein a lighttpd server as a proxy for different web server on my server. One of them is a rails app (Ruby 1.9.2/Rails 2.3.x) running with thin server.
I thought that I have to enable “mod_expire” in the lighttpd proxy and use the settings:
expire.url = ("/favicon.ico" => "access plus 7 days",
"/stylesheets/" => "access plus 7 days",
"/javascripts/" => "access plus 7 days",
"/images" => "access plus 7 days"
)
But it did not work. I also moved the expire.url code to:
$HTTP["host"] =~ "myRailsApp" {
expire.url = ...
proxy.balance = "fair"
proxy.server = (
"/" => (
(
"host" => "11.22.33.44",
"port" => 2000
),
(
"host" => "11.22.33.44",
"port" => 2001
)
)
}
It did not work, either.
So my question is: How can I enable the browser caching for my lighttpd/thin setting?
Unfortunately, Google did not help me.

It is also possible to use a condition, e.g.:
[
...]
$HTTP["url"] =~ "^/images/" {
expire.url = ( "" => "access plus 1 hours" )
}
[...]

Related

lighttpd url.rewrite to remove part of url

I'm trying to replace a part of my url before before delivering the file.
I call
localhost:8080/files/page_home.d41d8.js
and would like to modify the call to
/files/page_home.js
After that the file shall be delivered directly by lighttpd and not be forwareded to the fastcgi backend.
I tried the following:
server.modules += ( "mod_fastcgi", "mod_rewrite" )
url.rewrite = ("^/files/(([a-zA-Z0-9_]+))\.(([a-zA-Z0-9]))\.js$" => "/files/$1.js")
$HTTP["url"] !~ "^/files/" {
fastcgi.server = (
"/" => ((
"bin-path" => "/srv/www/cppapp/dist/Debug/GNU-Linux/cppapp.exe",
"bin-environment" => (
"LD_LIBRARY_PATH" => ""
),
"socket" => "/tmp/cppapp-fastcgi-socket",
# # only 1 process !
"max-procs" => 1,
"check-local" => "disable",
# "broken-scriptfilename" => "enable"
"fix-root-scriptname" => "enable",
))
)
}
When I'm looking into the log, the part ".d41d8." is not replaced.
Does anyone of you have a tip for replacing that part?
Thank you very much,
Alex
If someone is searching for answer in future: The problem was the regular expression "^/files/(([a-zA-Z0-9_]+)).(([a-zA-Z0-9])).js$". The second part was only matching one char / number. The correct version is "^/files/(([a-zA-Z0-9_]+)).(([a-zA-Z0-9]+)).js$"

How to get host under a host group, By Ruby script

I am able to get the host group id by
puts zbx.hostgroups.get(:name => "Dev" )
give this o/p
{"groupid"=>"13", "name"=>"Dev", "internal"=>"0", "flags"=>"0"}
But I want to get all the nodes under this host group. Although I tried in other way like
get all host under this host group but I didnt find groupid attribute in host please refer below o/p
puts zbx.hosts.get(:host => "ip-10-10-111-11.ec2.internal")
{"maintenances"=>[], "hostid"=>"10251", "proxy_hostid"=>"10109",
"host"=>"ip-10-10-111-11.ec2.internal", "status"=>"0",
"disable_until"=>"0", "error"=>"", "available"=>"1",
"errors_from"=>"0", "lastaccess"=>"0", "ipmi_authtype"=>"0",
"ipmi_privilege"=>"2", "ipmi_username"=>"", "ipmi_password"=>"",
"ipmi_disable_until"=>"0", "ipmi_available"=>"0",
"snmp_disable_until"=>"0", "snmp_available"=>"0",
"maintenanceid"=>"0", "maintenance_status"=>"0",
"maintenance_type"=>"0", "maintenance_from"=>"0",
"ipmi_errors_from"=>"0", "snmp_errors_from"=>"0", "ipmi_error"=>"",
"snmp_error"=>"", "jmx_disable_until"=>"0", "jmx_available"=>"0",
"jmx_errors_from"=>"0", "jmx_error"=>"",
"name"=>"ip-10-10-111-11.ec2.internal", "flags"=>"0", "templateid"=>"0"}
I didnot find any relation between hosts & hostgroups.
I got it working in the below manner
host_grps = zbx.query(
:method => "host.get",
:params => {
"output" => "extend",
"groupids" => [14]
}
)
puts host_grps
Its gives host groups in list of hashmap.
A simple JSON request for method host.get with the following parameters gives me information for all hosts that belong to the specified groups:
{ "output" : "extend", "groupids": [ "4", "12" ] }
Please consult host.get API documentation for more information.

Unable to enable crypto on TCP connection api.mysite.com on Zend

I was creating a module application for Zend Framework 2. When I try to send a post request to my server with the necessary details, I get the error "Unable to enable crypto on TCP connection api.mysite.com".
Earlier, I was getting the error "Unable to enable crypto on TCP connection api.mysite.com: make sure the "sslcafile" or "sslcapath" option are properly set for the environment."
On googling, I found I should set sslverifypeer to false. After doing this, I was left with the 1st part of the sentence "Unable to enable crypto on TCP connection api.mysite.com."
Not getting idea where I could be wrong.
Under previous exceptions, I get "stream_socket_enable_crypto(): this stream does not support SSL/crypto"
Please see this note in the docs: http://framework.zend.com/manual/2.3/en/modules/zend.http.client.html#connecting-to-ssl-urls . You shouldn't set sslverifypeer unless the site you're connecting to doesn't have a valid SSL certificate. Instead, set sslcapath as the error suggests. This gives PHP a way of validating the SSL certificate supplied by the host you're connecting to.
This is due to your site trying to communicate with a ssl used site. If you want to use default adapterZend\Http\Client\Adapter\Socket you have to define sslcapath configuration option in order to allow PHP to validate the SSL certificate.
To avoid this I used the curl adapter instead.
$client = new Client();
$client->setUri($endPointUrl);
$options = array('put your options');
$client->setOptions($options);
$client->setAdapter('Zend\Http\Client\Adapter\Curl');
$response = $client->send();
Doc : http://framework.zend.com/manual/current/en/modules/zend.http.client.html
You need to set Http Client Options.
Here is the working setting:
// eko/FeedBundle and issue with ssl site -> https://github.com/eko/FeedBundle/issues/51
$httpClientOptions = array(
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'persistent' => false,
'sslverifypeer' => false,
'sslallowselfsigned' => false,
'sslusecontext' => false,
'ssl' => array(
'verify_peer' => false,
'allow_self_signed' => true,
'capture_peer_cert' => true,
),
'useragent' => 'Feed Reader',
);
ZendFeedReader::setHttpClient(new ZendHttpClient(null, $httpClientOptions));
Here is the NOT working setting:
// eko/FeedBundle and issue with ssl site -> https://github.com/eko/FeedBundle/issues/51
$httpClientOptions = array(
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'persistent' => false,
'sslverifypeer' => false,
'sslallowselfsigned' => true,
'sslusecontext' => true,
'ssl' => array(
'verify_peer' => false,
'allow_self_signed' => true,
'capture_peer_cert' => true,
),
'useragent' => 'Feed Reader',
);
ZendFeedReader::setHttpClient(new ZendHttpClient(null, $httpClientOptions));
Note: I have issue with symfony bundle eko/feedBundle that use Zend library so essentially it is the same for you.
this solution tested and proven to be working.

hybridauth's social_hub/login.php doesn't work

I install the hybridauth on windows IIS, and setup the hybridauth\config.php as below:
array(
"base_url" => "http:///hybridauth/",
"providers" => array (
.....
"Google" => array (
"enabled" => true,
"keys" => array ( "id" => "<myappkey>", "secret" => "<myappsecret>" ),
"scope" => "email"
),
)
But when I click "Sign-in with Google" in http:///examples/social_hub/login.php, it just redirect me to http:///hybridauth/?hauth.start=Google&hauth.time=1401608000 which show the files under "localhost - /hybridauth/"
Anyone know how to fix it?
Thank you!
1) i am not sure if your scope is properly set up (you should have probably set it to "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email"
2) did you set up the return address in google api correct?

FedEx 556 - No valid services available. when there should be

Hi I'm trying to use the wsdl api to get shipping cost calculated for my website.
I'm using opencart and this module (http://www.opencart.com/index.php?route=extension/extension/info&extension_id=2055&filter_search=fedex&sort=e.date_modified&order=DESC).
On checkout I'm getting this error:
WARNING::556::There are no valid services available.
But I tried the same from and to address on the calculator on the fedex website and it gives me two services: International Priority and International Economy
This is the debug data I have:
Array
(
[WebAuthenticationDetail] => Array
(
[UserCredential] => Array
(
[Key] => REDACTED
[Password] => REDACTED
)
)
[ClientDetail] => Array
(
[AccountNumber] => REDACTED
[MeterNumber] => REDACTED
)
[TransactionDetail] => Array
(
[CustomerTransactionId] => *** Rate Request v9 using PHP ***
)
[Version] => Array
(
[ServiceId] => crs
[Major] => 9
[Intermediate] => 0
[Minor] => 0
)
[ReturnTransitAndCommit] => 1
[RequestedShipment] => Array
(
[DropoffType] => REQUEST_COURIER
[ShipTimestamp] => 2011-09-28T09:02:01+00:00
[PackagingType] => YOUR_PACKAGING
[TotalInsuredValue] => Array
(
[Amount] => 2000
[Currency] => EUR
)
[Shipper] => Array
(
[Address] => Array
(
[StreetLines] => Array
(
[0] =>
[1] =>
)
[City] => Ronchis
[StateOrProvinceCode] =>
[PostalCode] => 33050
[CountryCode] => IT
[Residential] => 1
)
)
[Recipient] => Array
(
[Address] => Array
(
[StreetLines] => Array
(
[0] =>
[1] =>
)
[City] => villach
[StateOrProvinceCode] =>
[PostalCode] => 9500
[CountryCode] => AT
[Residential] => 1
)
)
[ShippingChargesPayment] => Array
(
[PaymentType] => SENDER
[Payor] => Array
(
[AccountNumber] => 263150082
[CountryCode] => IT
)
)
[RateRequestTypes] => LIST
[PackageCount] => 1
[PackageDetailSpecified] => 1
[PackageDetail] => INDIVIDUAL_PACKAGES
[RequestedPackageLineItems] => Array
(
[0] => Array
(
[Weight] => Array
(
[Value] => 34
[Units] => KG
)
[Dimensions] => Array
(
[Length] => 48
[Width] => 53
[Height] => 122
[Units] => CM
)
)
)
)
)
----------
-- NUSOAP -- Array
(
[HighestSeverity] => WARNING
[Notifications] => Array
(
[Severity] => WARNING
[Source] => crs
[Code] => 556
[Message] => There are no valid services available.
[LocalizedMessage] => There are no valid services available.
)
[TransactionDetail] => Array
(
[CustomerTransactionId] => *** Rate Request v9 using PHP ***
)
[Version] => Array
(
[ServiceId] => crs
[Major] => 9
[Intermediate] => 0
[Minor] => 0
)
)
What should I do?
I just ran into this error, and it turned out that the issue was an invalid postal code. Double check that you are specifying the "Shipper" information correctly.
Also, if that doesn't work give the FedEx customer support phone number a try. We would not have figured this issue out without their help.
I was also having this issue .. but with Joomla, Virtuemart. Because the FedEx server is the same so may be my solution could help somebody else too..
Here are the main things what I fixed to fix this issue.
Product's Weight should be less than the limit if you've set any as Maximum Weight.
If you are using any packaging has more weight than FedEx's provided box i.e. 25KG BOX or 10KG box, then always use "Your Own packaging"
it's true, do keep an eye on ZIP===States (i was testing and put wrong state with different zip) And this ZIP should be added in "Shop's Address" because this is considered as FROM and the destination address as well.
Do note if products have added weights. LWH (Length, Width, Height).
Mine issue resolved after weeks of trouble! I wish somebody else could also resolve this issue if facing.
I was facing following error
"10 kg packaging box is **only** Available at FedEx World Service Center® locations!"
which was a big help to resolve the limitation i've set.
This issue happen when one of the bellow cases.
Country given is not associated with FedEx account.
Origin address is not real, Especially the post code.
The given packagingType is available in your country.
You need to provide a ServiceType. One of these:
EUROPE_FIRST_INTERNATIONAL_PRIORITY
FEDEX_1_DAY_FREIGHT
FEDEX_2_DAY
FEDEX_2_DAY_AM
FEDEX_2_DAY_FREIGHT
FEDEX_3_DAY_FREIGHT
FEDEX_EXPRESS_SAVER
FEDEX_FIRST_FREIGHT
FEDEX_FREIGHT_ECONOMY
FEDEX_FREIGHT_PRIORITY
FEDEX_GROUND
FIRST_OVERNIGHT
GROUND_HOME_DELIVERY
INTERNATIONAL_ECONOMY
INTERNATIONAL_ECONOMY_FREIGHT
INTERNATIONAL_FIRST
INTERNATIONAL_PRIORITY
INTERNATIONAL_PRIORITY_FREIGHT
PRIORITY_OVERNIGHT
SMART_POST
STANDARD_OVERNIGHT
Use it in the same level as the DropoffType
Make sure that you have the Zip Code set to required.
You can do that in System -> Localization -> Countries.
It is not required by default in opencart, and the fedex shipping system will not work without it.
This issue can also be caused by requesting insurance in a country that doesn't support it, such as Canada.
I also ran into this problem and the solution was trimming extra spaces from the end of the address, city & postal code. After that, all was well again.
I don't know why FedEx's API all of a sudden stopped accepting the extra spaces, but who knows...
In my case, this was caused by trying to ship internationally from the US to Italy, and having specified a SignatureOptionDetail of NO_SIGNATURE_REQUIRED. Changing this to SERVICE_DEFAULT fixed it.

Resources