Challenges that each developer faces every day: February 2010

Tuesday, February 23, 2010

nginx 502 Bad Gateway on Fedora Core 10

I just noticed that my web server (nginx) was returning nginx 502 Bad Gateway error for almost all of the sites.
Weird enough. I applied all available updates for Fedora Core 12 which upgraded nginx.
After the updates I decided to apply several new Kernels that were available listed in my Slicehost Control Panel under Kernel tab. It seems one of the kernels was causing nginx to return 502 Bad Gateway error.
I hope that will help somebody.

 Digg  Del.icio.us  Reddit  SlashDot

Javascript fix for flash content displaying on top of all elements

You may have a cms or widget that accepts posting/embeding videos from other sites.
Fore example with the youtube embed code "wmode" parameter is not specified so by definition
the flash will be placed on top of other elements.

Here is more info by Adobe: http://kb2.adobe.com/cps/155/tn_15523.html

Here is the javascript fix:

<html>
<body>

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'></script>

<script type='text/javascript'>
/*
We'll capture all the <object ...</object> tags if any.
Then we'll check if they have a <param ... name="wmode"></param> specific if yes we'll leave it as it is
If no we'll add <param value="transparent" name="wmode"></param> to the object and add an attrib to the embed element
to make the video go under the modo edit article buttons.
author: Svetoslav Marinov
email: slavi.[at].slavi.dot.biz
site: devcha.com
twitter: http://twitter.com/lordspace
license: LGPL
*/ 
function butt() {
    var buff = $('#aa').val();
    
    obj_regex = /<object[\w\s\-\r\f\n\t\v\W]*?<\/object>/gi;
    
    matches_arr = buff.match(obj_regex);

    if (matches_arr.length == 0) {
        return ;
    }
    
    for (i = 0; i < matches_arr.length; i++) {
        var str = matches_arr[i];

        // Let's add the wmode parameter if it's not present.
        if (str.toLowerCase().indexOf('wmode') == -1) {
             str = str.replace(/(<object[^>]*>)/gi, '$1' + "\n" + '<param value="transparent" name="wmode">' + "\n");
             str = str.replace(/(<embed)([^>]*>)/gi, '$1 wmode="transparent" $2');
             buff = buff.replace(matches_arr[i], str);
        }
    }

    $('#aa').val(buff);
    
    return buff;
}
</script>
<div>
<h3>This will make flash not overlap other objects by inserting wmode parameter/attribute.</h3>
    <textarea id="aa" style="width:750px;height:375px;">
        <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/upenR6n7xWY&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>
        <embed src="http://www.youtube.com/v/upenR6n7xWY&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>

        <object width="426" height="344"><param name="movie" value="http://www.youtube.com/v/upenR6n7xWY&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>
        <embed src="http://www.youtube.com/v/upenR6n7xWY&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="426" height="344"></embed></object>
       
           <object width="427" height="344"><param name="movie" value="http://www.youtube.com/v/upenR6n7xWY&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>
        <param value="transparent" name="wmode"></param>
        <embed src="http://www.youtube.com/v/upenR6n7xWY&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="427" height="344" wmode="transparent"></embed></object>
    </textarea>
    <p>
    <button type="button" onclick="butt();">Test Regex</button>
    </p>
</div>

</body>
</html>

 Digg  Del.icio.us  Reddit  SlashDot

Sunday, February 21, 2010

Enable gzip compression of nginx

I just realized that my Slicehost VPS wasn't running with gzip enabled by default.
Here is what I put into /etc/nginx/nginx.conf to make it work.

    ## Compression
    # src: http://www.ruby-forum.com/topic/141251
    # src: http://wiki.brightbox.co.uk/docs:nginx

    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_min_length  1100;
    gzip_buffers 16 8k;
    gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    
    # Some version of IE 6 don't handle compression well on some mime-types, so just disable for them
    gzip_disable "MSIE [1-6].(?!.*SV1)";
    
    # Set a vary header so downstream proxies don't send cached gzipped content to IE6
    gzip_vary on;
    ## /Compression

Don't forget to execute
 /etc/init.d/nginx reload

Note:
In the link to slicehost above I used my affiliate link so if you signup and keep the hosting for 3 months I will get some sort of credit.

 Digg  Del.icio.us  Reddit  SlashDot

Friday, February 19, 2010

Component returned failure code: 0x805e000a [nsIXMLHttpRequest.open]" nsresult: "0x805e000a

Have you seen this error in your firebug console ?

Component returned failure code: 0x805e000a [nsIXMLHttpRequest.open]" nsresult: "0x805e000a

I know it can be frustrating.

The smart guys from this site has figured out that Adblock Plus was causing this kind of errors.
So the solution is to disable it for your site.

Related

S

 Digg  Del.icio.us  Reddit  SlashDot

Wednesday, February 17, 2010

Solved: Incorrect value for DocumentRoot/DOCUMENT_ROOT Using Apache's mod_vhost_alias

The problem

It is a pretty good idea to use Apache for mass vhosting. You do the setup once and after that a vhost creation is just a matter of creating the folder structure.
The problem is that the DOCUMENT_ROOT environment variable is set incorrectly which points to the main vhost.

It seems it is a known bug see https://issues.apache.org/bugzilla/show_bug.cgi?id=26052 with the VirtualDocumentRoot parameter.

The Solution
Until it is fixed here is my solution that solves the problem globally.
It requires including a file (aka auto_prepend_file) which checks if the document root folder exists and sets it if it does.
It also saves the old document root folder just in case.

Add/edit /etc/php.ini with this value

auto_prepend_file = /var/www/vhosts/virtual.prepend.php


[admin@dev vhosts]$ cat /var/www/vhosts/virtual.prepend.php
<?php

// Let's fix the document root because of a bug in Apache's mod_vhost_alias not
// setting up the correct $_SERVER['DOCUMENT_ROOT'] env variable.
$__mod_vhost_alias_fix_doc_root = dirname(__FILE__) . DIRECTORY_SEPARATOR . $_SERVER['HTTP_HOST'] . DIRECTORY_SEPARATOR . 'htdocs';

if (is_dir($__mod_vhost_alias_fix_doc_root)) {
    $_SERVER['__MOD_VHOST_FIX_OLD_DOCUMENT_ROOT'] = $_SERVER['DOCUMENT_ROOT'];
        $_SERVER['DOCUMENT_ROOT'] = $__mod_vhost_alias_fix_doc_root;
}

?>

Do restart apache
apachectl restart
OR
/etc/init.d/httpd restart
OR
/etc/init.d/apache restart


My mass virtual host structure is: /var/www/vhosts/DOMAIN.TLD/htdocs

My vhost file (Fedora Core 12) saved in /etc/httpd/conf.d/zz_virtual.conf look like this.

SetEnv WS_DEVEL 1

#LogLevel debug

<Directory /var/www/vhosts>
      DirectoryIndex index.php index.html index.htm index.shtml
      Options Indexes FollowSymLinks Multiviews +Includes +ExecCGI
      AllowOverride All
</Directory>

<VirtualHost *:80>
   AccessFileName     .htaccess

   ServerAlias *
   UseCanonicalName Off
   LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon

   # Single location for all Apache access & error logs, delimited by URL
   CustomLog /var/www/vhosts/virtual.access.log vcommon
   ErrorLog /var/www/vhosts/virtual.error.log

   # Using vhost_alias, goto the true destination for new site
   VirtualDocumentRoot /var/www/vhosts/%0/htdocs
   VirtualScriptAlias /var/www/vhosts/%0/cgi-bin

   # the following may not work as expected so there is another directive above
   <Directory /var/www/vhosts/%0/htdocs>
      DirectoryIndex index.php index.html index.htm index.shtml
      Options Indexes FollowSymLinks Multiviews +Includes
      AllowOverride All
   </Directory>
</VirtualHost>


Related

 Digg  Del.icio.us  Reddit  SlashDot

Tuesday, February 9, 2010

Problems Creating Samba User on Fedora Core 12

The Problem

Summary: TB08997608 connection.py:630:call_blocking:DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

Traceback (most recent call last):
  File "/usr/share/system-config-samba/addUserWin.py", line 174, in on_add_user_ok_button_clicked
    elif self.samba_backend.userExists(unix_name):
  File "/usr/lib/python2.6/site-packages/scsamba/dbus/proxy/sambaBackend.py", line 88, in userExists
    return self.dbus_interface.userExists (user)
  File "/usr/lib/python2.6/site-packages/dbus/proxies.py", line 140, in __call__
    **keywords)
  File "/usr/lib/python2.6/site-packages/dbus/connection.py", line 630, in call_blocking
    message, timeout)
DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.

Local variables in innermost frame:
byte_arrays: False
self:
args: ('admin',)
utf8_strings: False
bus_name: dbus.UTF8String(':1.107')
get_args_opts: {'byte_arrays': False, 'utf8_strings': False}
object_path: '/org/fedoraproject/Config/Samba/Backend'
timeout: -1.0
signature: u's'
dbus_interface: 'org.fedoraproject.Config.Samba.Backend'
message:
method: 'userExists'

The Solution

start a Terminal (Applications > System Tools > Terminal) and then switch to root and execute the command /usr/bin/system-config-samba

admin@dev ~]$ su
Password: ....type your root password...
[root@dev admin]# system-config-samba
when you add a user (e.g. admin samba user) you should see an output such as:
Added user admin.

Before doing that I enabled and started smb and nmb services from System > Administration > Services
maybe that helped as well.
I also deactivated SE Linux and Disabled the Firewall (!)
Regarding the Firewall try to experiment with it enabled and only allow samba ports.
If you don't have another firewall before the Fedora server don't disable the firewall!!!
Consult your sysadmin so you don't expose unnecessary services.

Related
  • http://www.linuxquestions.org/questions/linux-software-2/samba-crashes-775289/
  • http://www.google.ca/search?q=Samba+DBusException%3A+org.freedesktop.DBus.Error.NoReply%3A+Did+not+receive+a+reply.+Possible+causes+include%3A+the+remote+application+did+not+send+a+reply&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

 Digg  Del.icio.us  Reddit  SlashDot