ApacheWebserver

From MyLinuxNotes

Jump to: navigation, search

Here is a portion of my /etc/httpd/conf/httpd.conf that rewrites any URL request to mypage.net/mail and anything below to append https:// to the front to force users to login via SSL.

  # Virtual host Virtual Host 1
  <VirtualHost 192.168.1.201:80>
        DocumentRoot /var/www/html/mypage/cgi-bin
        ServerAdmin admin@mypage.net
        ServerName mypage.net
        ErrorLog /var/log/httpd/mypage/error_log
        LogLevel warn
        HostnameLookups off
        ServerSignature email
        RewriteEngine on
        RewriteRule ^/mail/?.*$ https://%{SERVER_NAME}/mail/ [R,L]
        DirectoryIndex wiki.pl index.htm index.shtml index.html

        <Directory "/var/www/html/mypage/cgi-bin">
                AllowOverride none
                Options  ExecCGI
                Order allow,deny
                Allow from all

        </Directory>
  </VirtualHost>

I also wanted www appended to urls that that didn't already have it so I used this right after the RewriteEngine on line above:

    RewriteCond %{HTTP_HOST} ^linuxnotes.net$
    RewriteRule ^/(. ) http://www.linuxnotes.net/$1 [R]

After doing that I had to fix my mailman install because the lists were installed with http://linuxnotes.net not http://www.linuxnotes.net. To do this I added these lines to /etc/mailman/mm_cfg.py

   DEFAULT_URL_HOST = 'www.linuxnotes.net'
   add_virtualhost(DEFAULT_URL_HOST, DEFAULT_EMAIL_HOST)

and then ran:

   mailman/bin# ./withlist -la -r fix_url

This will fix all your lists. This will apply any changes made to /etc/mailman/mm_cfg.py.


I recently did a server migration from a RedHat box to a DebiaN one. One othe problems I ran into was trying to load my phpnuke site on Mozilla. I kept getting the error:

    Redirection limit for this URL exceeded.

Window$ Exploiter just showed a 404 error. I dug around trying to figure out how I caused a loop in my http.conf, but could not find anything. That was because it was a problem with MySQL. On my RedHat box I used localhost with no problems, but on DebiaN I needed to use 127.0.0.1 in my config.php to get it to work.


One day I found that apache was not running and a look in my apache logs showed:

   [notice] SIGUSR1 received.  Doing graceful restart

Well it did not restart. I tried to start it and got a Segentation Fault:

   linuxnotes:/var/log# /etc/init.d/apache start 
   Starting web server: apache/etc/init.d/apache: line 70: 21664 Segmentation fault      start-stop-daemon    
   --start --pidfile $PIDFILE --exec $DAEMON
   failed

I then tried reinstalling apache and it crapped out during the postinstall script:

    Error: 510mod_dynvhost.info does not have a valid LoadModule entry.
    Error: the above error list does not permit a safe use of modules-config.
    Please refer to the documentation on how to fix it or report it to
    Debian Apache Maling List <debian-apache@lists.debian.org> if in doubt
    on how to proceed
    dpkg: error processing apache (--configure):
     subprocess post-installation script returned error exit status 1
    Errors were encountered while processing:
     apache-ssl
     apache
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    linuxnotes:/var/log# cd 

Running modules-config gave me the same error.

I looked in /usr/lib/apache/1.3/510mod_dynvhost.info and found:

    LoadModule: dynvhost_module /usr/lib/apache/modules/mod_dynvhost.so
    LoadModule: dynvhost_module /usr/lib/apache/1.3/mod_dynvhost.so
    Directives:
            DynamicVirtualHost
    Description: Dynamic Virtual Hosting

I got rid of the first line, which got rid of the above error. Then I found this page that suggested that:

   % modules-config apache-perl disable mod_perl

"should do the trick.". It didn't for me, but it did tell me that apache-perl didn't seem to be installed :O! Installing apache-perl did fix all these problems. I have been using cgi scripts and have not had any problems until now. Don't know why but it's fixed now.

Actually this was the begining of my problems. The power in my office went out and when my server came back up no apache. I tried to start apache, it claimed that it started, added a pid to the pid file but no processes were present. There were no errors in my logs either. I found that mod_php4 was the cause of my woes, but I have not found a fix for apache.

As I stated above I installed apache-perl. apache-perl also would not start with mod_php4 enabled either. However I did find a solution. When I took a look in /etc/apache-perl/modules.conf I saw that mod_php4 was near the bottom of the list. I edited the file and moved it to the top of the LoadModule list and apache-perl worked. To fix this correctly I changed the name of /usr/lib/apache/1.3/500mod_php4.info to /usr/lib/apache/1.3/499mod_php4.info. The modules a loaded in order by the ### prefix. The modules are located in /usr/lib/apache/1.3.

Once again apache(-perl) crapped out on me (e.g., Segmetation Fault). There was nothing in the logs to indicate the problem. Apache-perl seemed to start with apache-perl-ctl start but then immediatly died. The only way I got any information was via apache-perl -X, which just showed it was segfaulting. I once again commented out the mod_php4 line in /etc/apache-perl/modules.conf and apache-perl started again. I then tried it at the end of the file and everything was fine. Looking in /usr/lib/apache/1.3/ I found both 499mod_php4.info and 500mod_php4.info. I deleted 499mod_php4.info and everything was cool.


Working on chrooting Apache MySQL PHP to use phpBB I ran into a bunch of problems. Most of them were because I didn't understand enough about chroot.

  • If you are using MySQL use TCP connections instead of trying to mess with sockets and use 127.0.0.1 instead of localhost.
  • One error I had a lot was ...failed to open stream: Permission denied... this had to do with file permissions in the chrooted directory. Specifically, /etc/phpbb2/config.php. Change the ownership to UID for Apache.
  • apache2ctl no longer works and returns this error:
   (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
   no listening sockets available, shutting down

Part of the problem is that Apache requires a full restart:

   $ apache2ctl stop
   $ apache2ctl start

To fix the error create a symlink to the apache2.pid file in your chroot directory:

   ln -s /chroot/apache2/var/run/apache2.pid /var/run/apache2.pid

This will be deleted on the next reboot. To try to make this static and "fix" the restart problem I added the following to the config section of /usr/sbin/apache2ctl:

   # path to the chroot directory
   CHROOT='/etc/apache2'
   # path to the PID file ouside of the chroot jail
   PID='/var/run/apache2.pid'

and this just above case $ARGV in:

   # This symlinking process is necessary to make apache2ctl aware of the
   # PID when not in the jail
   if ! [ -e $PID ]; then
       ln -s $CHROOT$PID $PID
   fi

Then I edited the case statement and split the case start|stop|restart|graceful) into several cases:

case $ARGV in
start|graceful)
    $HTTPD -k $ARGV
    ERROR=$?
    ;;
stop)
    $HTTPD -k $ARGV
    rm -f $PID
    ERROR=$?
    ;;
restart)
    $HTTPD -k stop
    rm -f $PID
    $HTTPD -k start
    ERROR=$?
    ;;
...



On an apt-get upgrade my Apache was upgraded from 2.0 to 2.2 and my SSL site stoped working (i.e., I was getting "transfer interrupted" errors in Firefox). Trying to start it with apache2ctl startssl gave me:

   The startssl option is no longer supported.
   Please edit httpd.conf to include the SSL configuration settings
   and then use apachectl start.

I finally figured it out after a lot of Googling. All I had to do was comment out the IfDefine SSL tags in my ssl.conf file and then restart the server.