Category Archives: ami

AWS Load Balancer: 503 (Service Unavailable: Back-end server is at capacity)

I setup a load balancer that is forwarding https (443) to https (443) on a simple EC2 nano with AMI Linux using a SSL cert from AWS. After some hours/days by opening the website over https I get a:

Failed to load resource: the server responded with a status of 503 (Service Unavailable: Back-end server is at capacity)

It is redirecting all requests on port 80 to 443 using the .htaccess file.

That is really really annoying. What is wrong in my configuration?

Loop redirect error during installation of SSL Certificates on ubuntu ami

I tried to install SSL certicates on my ubuntu server. I followed this link for installation. But after following all the steps I am getting loop redirect error. Below are the configurations of my /etc/apache2/sites-enables/000-default.conf file.

<VirtualHost *:80>
        ServerName example.com
        Redirect permanent / https://example.com/
</VirtualHost>

and then some rules for subdomain of example.com. After that rules for "example.com"

<VirtualHost *:443>
        # LAUNCH WEBSITE
        ServerName example.com:443
        #ServerAlias example.com
        SSLEngine on
        SSLCertificateFile /home/ubuntu/example.com.crt
        SSLCertificateKeyFile /home/ubuntu/example.key
        SSLCertificateChainFile /home/ubuntu/intermediate.crt
        DocumentRoot "/var/www/Production/launch_website"
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        <directory /var/www/Production/launch_website>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        </directory>
</VirtualHost>

These SSL certicates are valid only for domain not for subdmoains. I don't have any .htaccess file for "launch_website" folder and I am using apache version 2.4.7.

Apache memory forcing mysqld to crash on aws linux ami

I recently setup a fresh AWS Linux AMI x64 instance for a friend to house their wordpress site. I followed the following instructions:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html

After successfully launching the site for the user, they started to write their first few posts, and learn how to navigate wordpress.

A day or two later....

I was informed that the site would constantly have database errors which crashed the website.

Error establishing a database connection

After further investigation i noticed that the httpd tasks where stealing all the memory and crashing mysqld due to memory exhaustion.

             total       used       free     shared    buffers     cached
Mem:           995        985         10          0          0         19
-/+ buffers/cache:        965         30
Swap:            0          0          0


top - 05:23:33 up  1:09,  1 user,  load average: 57.94, 40.81, 23.27
Tasks: 155 total,  54 running, 101 sleeping,   0 stopped,   0 zombie
Cpu(s): 17.7%us,  3.8%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.3%si, 78.2%st
Mem:   1019340k total,  1010600k used,     8740k free,      808k buffers
Swap:        0k total,        0k used,        0k free,    20884k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 6251 apache    20   0  404m  35m 9200 S  1.3  3.6   0:01.71 httpd
 6212 apache    20   0  404m  31m 5068 R  2.3  3.2   0:02.72 httpd
 6187 apache    20   0  400m  31m 4764 R  1.0  3.1   0:03.08 httpd
 6184 apache    20   0  404m  31m 4604 R  2.0  3.1   0:03.26 httpd
 6177 apache    20   0  404m  31m 4568 R  2.0  3.1   0:03.26 httpd
 6171 apache    20   0  404m  30m 4296 S  0.0  3.1   0:03.19 httpd
 6220 apache    20   0  404m  30m 4224 S  0.0  3.1   0:02.63 httpd
 5708 apache    20   0  404m  30m 4304 R  2.0  3.0   0:08.70 httpd
 6127 apache    20   0  404m  29m 3356 S  0.0  3.0   0:03.44 httpd
 6200 apache    20   0  404m  29m 2952 S  0.0  3.0   0:02.65 httpd
 5711 apache    20   0  404m  28m 2496 R  2.0  2.9   0:08.58 httpd
 6211 apache    20   0  405m  28m 2016 R  1.7  2.8   0:02.87 httpd
 6150 apache    20   0  403m  28m 2332 R  2.0  2.8   0:03.60 httpd
 5967 apache    20   0  403m  27m 2188 R  2.0  2.8   0:05.84 httpd
 5889 apache    20   0  403m  27m 1956 R  2.3  2.7   0:06.72 httpd
 6207 apache    20   0  400m  25m 3424 R  1.0  2.6   0:02.83 httpd
 6313 apache    20   0  400m  25m 3132 S  0.0  2.5   0:01.14 httpd

The only installed the following:

sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd php56-gd

What would be causing httpd to create a fair few tasks and steal all 1gb of memory on a website that has no activity bar one user?

How to allow incoming traffic based on User-Agent Header field with Apache

I have read the documentation on Apache's setEnvIf and, using their example, written the following httpd config file designed to only allow requests from HTTP Header User-Agent=Doug

SetEnvIfNoCase User-Agent Doug let_me_in
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None

Order deny,allow
Deny from all
Allow from env=let_me_in
</Directory>

Upon using Postman to send the request with the User-Agent being Doug, the request was denied. I have also tried switching the order to allow,deny to no avail.

I am running Amazon AMI and using Apache 2.2.31

Rails log to Apache error_log instead production.log

I'm using Rails 3.2.17, with Apache2.4.12 and Passenger 5.0.6 in an Amazon Linux instance. My production.log file remains empty, while every single log line is written in Apache's error_log. I checked file permissions (actually changed production.log to 666) and that the app was running in production environment. Any thoughts?

EDIT:

In response to @usmanali comment, I get everything I should get in production.log, as a sample:

App 32308 stdout: Processing by DemoController#index as HTML
App 32308 stdout: Redirected to http://myapp.com/action
App 32308 stdout: Filter chain halted as :redirect_if_authenticated rendered or redirected
App 32308 stdout: Completed 302 Found in 20.5ms
App 32308 stdout: Started GET "/action" for 890.1400.960.460 at 2015-04-15 08:56:02 +0000
App 32308 stdout: Processing by Controller#index as HTML
App 32308 stdout:   Rendered templates/_left_menu.html.haml (1.7ms)
App 32308 stdout:   Rendered templates/_list.html.haml (27.4ms)
App 32308 stdout:   Rendered templates/index.html.haml within layouts/application (33.9ms)
App 32308 stdout: Completed 200 OK in 249.5ms (Views: 43.6ms)

PHP not running after upgrade

I'm having some trouble getting PHP to run under Apache after updating my software. On my Amazon AWS running AMI, I followed this guide here, with the specific commands:

  • sudo yum remove httpd* php*
  • sudo yum install httpd24 php55

After updating the apache config files to use the newer directives, I can get to the server, but the PHP is just echoing out on the screen.

I checked to make sure that there is a php.ini file being read, that the module is loaded in Apache, the server is running, and I can execute php from the command line.

Anyone have any ideas on what I should check next?

Cannot create new application through web2py admin interface – Permission denied

I have deployed web2py and integrated it with apache on my redhat linux AMI according to the instructions given at

http://www.web2pyslices.com/slice/show/1423/deploy-web2py-on-fedoracentosred-hat

Everything is working fine. I can open welcome page on port 80 and 443. When I try to access admin interface over HTTP, request gets denied as expected. But when I try to access interface over HTTPS, it asks for password. When I enter the password which I set while installation it redirects me to error page with some ticket number. When I click on the link it asks for me to provide admin password again. So I tried to read the file from errors folder of web2py application. This file says

IOError: [Errno 13] Permission denied: \'/web2py/applications/admin/private/hosts.deny\'\n'

I thought this might be related to permissions so I gave full access to hosts.deny file. It is still exhibiting the same behavior. Please help me out.


Above problem has been solved by deleting existing hosts.deny file. Now I am able to access admin interface. However when I try to create a new application it doesn't allow and shows error message :

Traceback (most recent call last):
  File "/web2py/gluon/admin.py", line 163, in app_create
    os.mkdir(path)
OSError: [Errno 13] Permission denied: '/web2py/applications/adv01'

I have checked out permissions of applications directory in web2py and it has drwxr-xr-x. access to apache user which also is its owner. I changed the permissions of the directory to drwxrwxrwx but it made no difference. Why is it still denying access?