Solved

Apache2 configuration

Posted on 2011-03-14
23
706 Views
Last Modified: 2012-05-11
I´ve installed UBUNTU 10 server and apache2. If type 127.0.0.0 or myip on the browser it´s working fine. But if I type mydomain.com I received an error. I have created mydomain folder under /var/www and I have index.html and index.php files there. I also created mydomain.com files on sites-availables and sites-enables folders
0
Comment
Question by:Jose Bredariol
  • 12
  • 11
23 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 35132680
Check if the apache is running

netstat -antp | grep 80


What is your DocumentRoot in your Virtual Host?  Is it /var/www/mydomain.com?  Is mydomain.com a file or a folder?
0
 

Author Comment

by:Jose Bredariol
ID: 35132885
Yes,
 tcp        0      0 0.0.0.0:80              0.0.0.0:*               List
1538/apache2  


on /sites-enables/www.sbaedu.com.br file I have

NameVirtualHost *:80

<VirtualHost *:80>
        ServerAdmin webmaster@sbaedu.com.br
        ServerName www.sbaedu.com.br
        ServerAlias *.sbaedu.com.br

        DocumentRoot /var/www/www.sbaedu.com.br
        <Directory /var/www/www.sbaedu.com.br>
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
              # This directive allows us to have apache2's default start page
                # in /apache2-default/, but still have / go to the right place
                #RedirectMatch ^/$ /apache2-default/
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>


        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

0
 
LVL 31

Expert Comment

by:farzanj
ID: 35133373
So as per your configuration, your index.html file should be placed under /var/www/www.sbaedu.com.br directory.

Please do this:

ls -ld /var/
ls -ld /var/www/
ls -ld /var/www/www.sbaedu.com.br
ls -l /var/www/www.sbaedu.com.br
0
 

Author Comment

by:Jose Bredariol
ID: 35137235
Yes, I have at /var/www/www.sbaedu.com.br index.html and index.php files.
ls -ld /var
drwxr-xr-x 16 root root 4096 2011-03-11 15:51 /var

ls -ld /var/www/
drwxr-xr-x 3 root root 4096 2011-03-14 15:02 /var/www

ls -ld /var/www/www.sbaedu.com.br
drwxr-xr-x 5 root root 4096 2011-03-14 16:54 /var/www/www.sbaedu.com.br/

ls -l /var/www/www.sbaedu.com.br
total 52
drwxr-xr-x 2 root root  4096 2011-03-14 15:14 cgi-bin
-rw-r--r-- 1 root root   200 2011-03-14 16:54 index.html
-rw-r--r-- 1 root root   140 2011-03-14 17:00 index.php
drwxr-xr-x 2 root root  4096 2011-03-14 15:13 logs
drwxr-xr-x 3 root root 36864 2011-03-14 12:02 moodle

0
 
LVL 31

Expert Comment

by:farzanj
ID: 35137425
These files should be owned by apache user.  At least index.php should be world executable as well.

drwxr-xr-x 2 root root  4096 2011-03-14 15:14 cgi-bin
-rw-r--r-- 1 root root   200 2011-03-14 16:54 index.html
-rw-r--r-- 1 root root   140 2011-03-14 17:00 index.php
drwxr-xr-x 2 root root  4096 2011-03-14 15:13 logs
drwxr-xr-x 3 root root 36864 2011-03-14 12:02 moodle

What is the value of the attribute
DirectoryIndex?
0
 

Author Comment

by:Jose Bredariol
ID: 35137488
Where I can find the value of DirectoryIndex ?
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35137603
In file : /etc/httpd/conf/httpd.conf

Search for DirectoryIndex

It should contain index.html index.php

Like
DirectoryIndex index.html index.php

Issue the following command
netstat -lntpu | grep http

Second

Look for Listen
It should be:

IP-ADDR is the IP address where you want it to listen
Listen <IP-ADDR>:80
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35137612
These parameters will be there but they may be commented with #
Remove # to uncomment them
0
 

Author Comment

by:Jose Bredariol
ID: 35137644
In mods-enabled/dir.conf

<IfModule mod_dir.c>

          DirectoryIndex index.html index.cgi index.pl index.php index.xhtml in$

</IfModule>
----------------------------------------------------------------------------------
I don´t have this :
etc/httpd/conf/httpd.conf
I´m using apache2
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35137688
What is the name of your config file?

What is the exact version of your Apache?

You have to "Listen" on the correct IP address, as I instructed above

show me the output of this command

netstat -ltpud | grep http

0
 

Author Comment

by:Jose Bredariol
ID: 35137748
sudo netstat -ltpud | grep http
Nothing happened

My Ip is 192.168.0.253
Apache/2.2.16 (Ubuntu) Server at 192.168.0.253 Port 80

I´m using apache2.conf
/etc/apache2/sites/enabled/www.sbaedu.com.br


admsmd@serverbmd:/etc$ sudo Listen 192.168.0.253:80
sudo: Listen: command not found
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 31

Expert Comment

by:farzanj
ID: 35137781
You are almost using the same version of Apache as I am, the difference is that I am using Red Hat, so the name of config is different.

Listen is also in your httpd.conf file.  I was telling you the config options.

If you did not receive any output from your netstat command, that simply means that the service is not running
0
 

Author Comment

by:Jose Bredariol
ID: 35137853
I have httpd.con file on apache2 dir, but the file is empty.
Bellow is my apache2.conf file :


#
# Based upon the NCSA server configuration files originally by Rob McCool.
#
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.2/ for detailed information about
# the directives.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# The configuration directives are grouped into three basic sections:
#  1. Directives that control the operation of the Apache server process as a
#     whole (the 'global environment').
#  2. Directives that define the parameters of the 'main' or 'default' server,
#     which responds to requests that aren't handled by a virtual host.
#     These directives also provide default values for the settings
#     of all virtual hosts.
#  3. Settings for virtual hosts, which allow Web requests to be sent to
#     different IP addresses or hostnames and have them handled by the
#     same Apache server process.
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so "foo.log"
# with ServerRoot set to "/etc/apache2" will be interpreted by the
# server as "/etc/apache2/foo.log".
#

### Section 1: Global Environment
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests it can handle or where it
# can find its configuration files.
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation (available
# at <URL:http://httpd.apache.org/docs/2.2/mod/mpm_common.html#lockfile>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
LockFile ${APACHE_LOCK_DIR}/accept.lock

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 15

##
## Server-Pool Size Regulation (MPM specific)
##

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadLimit: ThreadsPerChild can be changed to this maximum value during a
#              graceful restart. ThreadLimit can only be changed by stopping
#              and starting Apache.
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

# event MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_event_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>

# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#

AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy all
</Files>

#
# DefaultType is the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType text/plain


#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

# Include module configuration:
Include mods-enabled/*.load
Include mods-enabled/*.conf

# Include all the user configurations:
Include httpd.conf

# Include ports listing
Include ports.conf

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

ServerName apache2serversba

# Include generic snippets of statements
Include conf.d/

# Include the virtual host configurations:
Include sites-enabled/
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35137879
I mean wherever you configuration is:

netstat -antpu

Should show http running.
0
 

Author Comment

by:Jose Bredariol
ID: 35137898
Conexes Internet Ativas (servidores e estabelecidas)
Proto Recv-Q Send-Q Endereo Local          Endereo Remoto         Estado       PID/Program name
tcp        0      0 0.0.0.0:993             0.0.0.0:*               OUA       852/dovecot    
tcp        0      0 0.0.0.0:995             0.0.0.0:*               OUA       852/dovecot    
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               OUA       1135/mysqld    
tcp        0      0 0.0.0.0:139             0.0.0.0:*               OUA       847/smbd        
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               OUA       1713/vino-server
tcp        0      0 0.0.0.0:110             0.0.0.0:*               OUA       852/dovecot    
tcp        0      0 0.0.0.0:143             0.0.0.0:*               OUA       852/dovecot    
tcp        0      0 0.0.0.0:10000           0.0.0.0:*               OUA       1605/perl      
tcp        0      0 0.0.0.0:80              0.0.0.0:*               OUA       1544/apache2    
tcp        0      0 192.168.122.1:53        0.0.0.0:*               OUA       1213/dnsmasq    
tcp        0      0 192.168.0.253:53        0.0.0.0:*               OUA       1072/named      
tcp        0      0 127.0.0.1:53            0.0.0.0:*               OUA       1072/named      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               OUA       1303/sshd      
tcp        0      0 127.0.0.1:631           0.0.0.0:*               OUA       1024/cupsd      
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               OUA       1200/postgres  
tcp        0      0 127.0.0.1:953           0.0.0.0:*               OUA       1072/named      
tcp        0      0 0.0.0.0:445             0.0.0.0:*               OUA       847/smbd        
tcp        0      0 192.168.0.253:5900      192.168.0.59:62796      ESTABELECIDA 1713/vino-server
tcp        0      0 192.168.0.253:445       192.168.0.25:49194      ESTABELECIDA 2125/smbd      
tcp6       0      0 :::5900                 :::*                    OUA       1713/vino-server
tcp6       0      0 :::53                   :::*                    OUA       1072/named      
tcp6       0      0 :::22                   :::*                    OUA       1303/sshd      
tcp6       0      0 ::1:631                 :::*                    OUA       1024/cupsd      
tcp6       0      0 ::1:5432                :::*                    OUA       1200/postgres  
tcp6       0      0 ::1:953                 :::*                    OUA       1072/named      
udp        0      0 0.0.0.0:53627           0.0.0.0:*                           912/avahi-daemon: r
udp        0      0 192.168.122.1:53        0.0.0.0:*                           1072/named      
udp        0      0 192.168.122.1:53        0.0.0.0:*                           1213/dnsmasq    
udp        0      0 192.168.0.253:53        0.0.0.0:*                           1072/named      
udp        0      0 127.0.0.1:53            0.0.0.0:*                           1072/named      
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1213/dnsmasq    
udp        0      0 192.168.0.255:137       0.0.0.0:*                           1364/nmbd      
udp        0      0 192.168.0.253:137       0.0.0.0:*                           1364/nmbd      
udp        0      0 192.168.122.255:137     0.0.0.0:*                           1364/nmbd      
udp        0      0 192.168.122.1:137       0.0.0.0:*                           1364/nmbd      
udp        0      0 0.0.0.0:137             0.0.0.0:*                           1364/nmbd      
udp        0      0 192.168.0.255:138       0.0.0.0:*                           1364/nmbd      
udp        0      0 192.168.0.253:138       0.0.0.0:*                           1364/nmbd      
udp        0      0 192.168.122.255:138     0.0.0.0:*                           1364/nmbd      
udp        0      0 192.168.122.1:138       0.0.0.0:*                           1364/nmbd      
udp        0      0 0.0.0.0:138             0.0.0.0:*                           1364/nmbd      
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           912/avahi-daemon: r
udp        0      0 0.0.0.0:10000           0.0.0.0:*                           1605/perl      
udp6       0      0 :::42367                :::*                                912/avahi-daemon: r
udp6       0      0 :::53                   :::*                                1072/named      
udp6       0      0 :::5353                 :::*                                912/avahi-daemon: r
udp6       0      0 ::1:54624               ::1:54624               ESTABELECIDA 1200/postgres  
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35137965
Ok.

It is running

tcp        0      0 0.0.0.0:80              0.0.0.0:*               OUA       1544/apache2


Also either enable mods-enabled/dir.conf or give this directive in the config file

DirectoryIndex index.html index.php
0
 

Author Comment

by:Jose Bredariol
ID: 35138046
mods.enabled/dir.conf :

<IfModule mod_dir.c>
          DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.html
</IfModule>
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35138193
Do you still have the same problem.  Restart the service.  It appears your problem should be resolved.
0
 

Author Comment

by:Jose Bredariol
ID: 35138292
Yes, I´m still having the problem. look this :
If I type :
http://192.168.0.253/www.sbaedu.com.br/index.php
it working

If I type :
http://www.sbaedu.com.br/index.php
it´s not working

If I type :
http://192.168.0.253
it´s  working

0
 
LVL 31

Accepted Solution

by:
farzanj earned 125 total points
ID: 35138327
Oh,

Put the following in your /etc/hosts

192.168.0.253      www.sbaedu.com.br
0
 

Author Comment

by:Jose Bredariol
ID: 35138471
Thanks, now it´s working.
Now, how can I access it from my intranet.
If I type
192.168.0.253/www.sbaedu.com.br
It´s working from my clients, but I want them to access only typing www.sbaedu.com.br
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35138548
You will either have to set /etc/hosts entries on all hosts or setup DNS.

If you setup DNS, you will have to make sure that in /etc/resolv.conf

Oh, too much work for 125 points :)

Glad it worked.
0
 

Author Closing Comment

by:Jose Bredariol
ID: 35138652
Ok, thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Users are often faced with high disk consumption without really knowing where the largest amount of data resides. Disk Usage Analyzer (aka Baobab) is is a graphical, menu-driven application to analyse disk usage in any Gnome environment and can e…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now