Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

20 February 2018

APACHE - failed to start

[On]
Red Hat Enterprise Linux Server release 7.4 (Maipo)

Apache was not running and attempt to start the httpd service failed. The natural thing as a sysadmin you would check the error_log. 

# systemctl restart httpd
# tail -f /var/log/httpd/error_log (location could be different on your installation)
--- error snippet---
[Tue Feb 20 17:57:32.667940 2018] [auth_digest:error] [pid 6256] (28)No space left on device: AH01762: Failed to create shared memory segment on file /run/httpd/authdigest_shm.6256
[Tue Feb 20 17:57:32.667948 2018] [auth_digest:error] [pid 6256] (28)No space left on device: AH01760: failed to initialize shm - all nonce-count checking, one-time nonces, and MD5-sess algorithm disabled
--- error snippet---

2 things to observe here. 
  1. no space left of device
  2. failed to create shared memory
As it turns out /run partition was used up 100% - which explains the subsequent error -  no. 2. 

Basically - the issue here is Apache has been leaving some stuff behind in shared memory. So the next command list those stuffs 

# ipcs -s (s is semaphores)

--- output ---
------ Semaphore Arrays --------
key        semid      owner      perms      nsems
0x00000000 3375104    apache     600        1
0x00000000 3407873    apache     600        1
0x00000000 2359298    apache     600        1
0x00000000 3440643    apache     600        1
0x00000000 3473412    apache     600        1
0x00000000 3506181    apache     600        1
--- output ---

You may proceed to remove the semaphores (apache only) by executing this command
# ipcrm -s  {semid} (if possible one after another)

Then proceed with restarting the httpd service
# systemctl restart httpd
# systemctl status httpd (verify Apache is running)
# ipcs -s (verify the semaphores are cleared)

Also, it is a good practice to reboot your machine once in 2 or 3 months that will actually clear the unused semaphores. 

7 February 2018

APACHE - Accessing multiple domain names using port 80

If you plan to publish 2 or more domain urls from the same apache server, this configuration will help you but the requirement is the document root path should be different for all domains.

<VirtualHost *:80>
       ServerName my-server1.com
       DocumentRoot /var/www/html/my-app1
    <Directory /var/www/html/my-app1>
Options FollowSymLinks
AllowOverride All
    Require all granted
    </Directory>
</VirtualHost>


<VirtualHost *:80>
       ServerName my-server2.com
       DocumentRoot /var/www/html/my-app2
    <Directory /var/www/html/my-app2>
Options FollowSymLinks
AllowOverride All
    Require all granted
    </Directory>
</VirtualHost>

<VirtualHost *:80>
       ServerName my-server3.com
       DocumentRoot /var/www/html/my-app3
    <Directory /var/www/html/my-app3>
Options FollowSymLinks
AllowOverride All
    Require all granted
    </Directory>
</VirtualHost>

APACHE - Reverse Proxy using root (/)

This took me days to figure out. I am happy to share with you guys who are wondering how to setup a reverse proxy. 

<VirtualHost *:8081>
       ServerName my-server
       DocumentRoot /var/www/html/my-app
       RewriteEngine On
       <Directory /var/www/html/my-app/>
      Options FollowSymLinks
              AllowOverride All
      Require all granted
       </Directory>
ProxyRequests Off
ProxyPreserveHost On

<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://{internal-app-server-ip}/
ProxyPassReverse / http://{internal-app-server-ip}/

</VirtualHost>

Save it and restart apache service.

When you access http://my-server:8081 in a browser apache will interpret the configuration above and redirects the url to http://{internal-app-server-ip}/ - internally while preserving the originating url in your browser which is http://my-server:8081. 

APACHE - If application path differs from DocumentRoot

If you are given a requirement where the application path does not reside in the default DocumentRoot defined in the apache config, then do this.

Define your Alias in httpd.conf. This is done in Apache on Windows server which is similar
if you are on Linux server - need to define your path accordingly.

    Alias "/{app-name}" "C:\{app-path}"
    <Directory "C:\{app-path}">
    Require all granted
    </Directory>

Save it and restart apache services. 




APACHE - Redirect URL containing an IP address to domain name

[On]
Red Hat Enterprise Linux Server release 7.4 (Maipo)

Please insert the Rewrite conditions as follows in the .htaccess file located in your DocumentRoot directory.

--- Change the IPs accordingly. ---

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^10\.24\.19\.85$ [OR]
    RewriteCond %{HTTP_HOST} ^10\.24\.19\.109$
    RewriteRule ^(.*)$ https://{DOMAIN_NAME}/$1 [L,R=301]
</IfModule>

4 April 2011

APACHE - Basic performance tuning

If you are running into frequent Apache crashes you can check the error_log for MaxClients-related problems.

To check your error logs to see if you have MaxClient issues you can run the following command as root: 


# grep -i maxclient /var/log/httpd/error_log*

If this command returns any results after making the above changes you may need to fine-tune the MaxClients variables further.

The official documentation on these settings and many others can be found here:
 
http://httpd.apache.org/docs-2.0/mod/mpm_common.html

Wordpress - Local installation in Vmware

If you're interested in exploring website design with WordPress, this guide will help you set up a WordPress instance on your local mach...