1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I need help with apache

Discussion in 'Apache' started by Metrik, Feb 26, 2014.

  1. #1
    i am try to run 2 apache2 web servers from one external ip.
    example: i want to be able to type in www.metrikcorp.com and go to apache server1
    or
    i want to type in admin.metrikcorp.com and go to apache server2
     
    Metrik, Feb 26, 2014 IP
  2. HassanKhalid

    HassanKhalid Active Member

    Messages:
    158
    Likes Received:
    6
    Best Answers:
    4
    Trophy Points:
    90
    #2
    With the power of Apache’s reverse proxy and virtual hosts, you are able to get around the limitations of hosting multiple physical servers behind a single public IP.
     
    HassanKhalid, Feb 26, 2014 IP
  3. Metrik

    Metrik Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    Thanks for the info.Do you know of any good tutorials on this?
     
    Metrik, Feb 27, 2014 IP
  4. HassanKhalid

    HassanKhalid Active Member

    Messages:
    158
    Likes Received:
    6
    Best Answers:
    4
    Trophy Points:
    90
    #4
    How To Setup Apache Virtual Host Configuration

    1. Uncomment httpd-vhosts.conf in httpd.conf

    2. Setup virtual hosts
    Modify the httpd-vhosts.conf as shown below to setup named-based virtual host setting for two hosts.
    • NameVirtualHost *:80 – Indicates that all the name-based virtual hosts will be listening on the default port 80
    • <VirtualHost *:80> </VirtualHost> – Enclose all the apache configuration parameters for each and every virtual host between these VirtualHost tags. Any apache directives can be used within the virtualhost container.
    • In the following example, we are setting up virtual host for name1.com and name2.com listening on the same port 80. So, there will be two <VirtualHost *:80> </VirtualHost>, one for each website.
    • When you go to name1.com, the files under /usr/local/apache2/docs/name1 will be served by Apache; and the access_log and error_log for this site will go under /usr/local/apache2/logs/name1
    # vi /usr/local/apache2/conf/extra/httpd-vhosts.conf[/SIZE][/SIZE]
    [SIZE=6][SIZE=4]NameVirtualHost *:80
    
    <VirtualHost *:80>
        ServerAdmin hasan@name1.com
        DocumentRoot "/usr/local/apache2/docs/name1"
        ServerName name1.com
        ServerAlias www.name1.com
        ErrorLog "logs/name1/error_log"
        CustomLog "logs/name1/access_log" common
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerAdmin hasan@name2.com
        DocumentRoot "/usr/local/apache2/docs/name2"
        ServerName name2.com
        ServerAlias www.name2.com
        ErrorLog "logs/name2/error_log"
        CustomLog "logs/name2/access_log" common
    </VirtualHost>
    Code (markup):
    3. Check VirtualHost Configuration Syntax
    Verify virtual configuration syntax using “httpd -S” as shown below. When everything is setup properly, it just displays “Syntax OK”.

    # /usr/local/apache2/bin/httpd -S[/SIZE][/SIZE]
    [SIZE=6][SIZE=4]VirtualHost configuration:
    Syntax OK
    Code (markup):
    When something is not configured properly, it will display warning message, including “directory does not exit” message as shown below.

    # /usr/local/apache2/bin/httpd -S[/SIZE][/SIZE]
    [SIZE=6][SIZE=4]Warning: DocumentRoot [/usr/local/apache2/docs/name2] does not exist
    Warning: ErrorLog [/usr/local/apache2/logs/name1] does not exist
    Syntax OK
    Code (markup):
    4. Restart the Apache and test

    # /usr/local/apache2/bin/apachectl restart
    Code (markup):
     
    Last edited: Feb 27, 2014
    HassanKhalid, Feb 27, 2014 IP
  5. Aeden

    Aeden Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    http://httpd.apache.org/docs/2.2/vhosts/examples.html
    Has some beautiful examples, tutorials, and documentation to do what you need to do.
     
    Aeden, Feb 28, 2014 IP
  6. Metrik

    Metrik Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #6
    i can get the vhost to work and i can get my first server by typing www.metrikcorp.com. but i still cant figure out how to get it to reach my second server at admin.metrikcorp.com.
    i dont undestaned how to access second server with the vhost cause if i just put in the local ip for that server it wont work for the outside world.
    <VirtualHost 192.168.1.4:80>
    # The ServerName directive sets the request scheme, hostname and port th$
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    ServerName metrikcorp.com
    ServerAlias www.metrikcorp.com
    DocumentRoot /var/www/metrikcorp.com/public_html

    # 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

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>

    <VirtualHost 192.168.1.10:80>
    ServerAdmin webmaster@localhost
    ServerName admin.metrikcorp.com
    ServerAlias admin.metrikcorp.com
    DocumentRoot /var/www
    </VirtualHost>
     
    Metrik, Feb 28, 2014 IP
  7. Metrik

    Metrik Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #7
    this is how my config is set u.
    <VirtualHost 192.168.1.4:80>
    ServerAdmin webmaster@localhost
    ServerName metrikcorp.com
    DocumentRoot /var/www/metrikcorp.com/public_html
    <Directory />
    Options FollowSymLinks
    AllowOverride ALL
    </Directory>
    <Directory /var/www/metrikcorp.com/public_html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride ALL
    Order allow,deny
    allow from all
    </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 ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    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>
    <VirtualHost 192.168.1.10:80>
    ServerAdmin webmaster@localhost
    ServerName admin.metrikcorp.com

    DocumentRoot /var/www/admin.metrikcorp.com/public_html
    <Directory />
    Options FollowSymLinks
    AllowOverride All
    </Directory>
    <Directory /var/www/admin.metrikcorp.com/public_html/>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>


    ErrorLog ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    </VirtualHost>

    but when i reload apache i get this error
    The apache2 configtest failed. Not doing anything.
    Output of config test was:
    AH00112: Warning: DocumentRoot [/var/www/admin.metrikcorp.com/public_html] does not exist

    dont understand what i am doing wrong any advice would be nice.
    Thanks
     
    Metrik, Mar 2, 2014 IP
  8. HassanKhalid

    HassanKhalid Active Member

    Messages:
    158
    Likes Received:
    6
    Best Answers:
    4
    Trophy Points:
    90
    #8
    Add it in the beginning of your file :
    NameVirtualHost *:80
    Code (markup):
     
    HassanKhalid, Mar 2, 2014 IP
  9. Metrik

    Metrik Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #9
    Hey thanks for the info.
    This is the code i tried to use"
    NameVirtualHost *:80
    <VirtualHost 192.168.1.4:80>
    ServerAdmin webmaster@localhost
    ServerName metrikcorp.com
    DocumentRoot /var/www/metrikcorp.com/public_html
    <Directory />
    Options FollowSymLinks
    AllowOverride ALL
    </Directory>
    <Directory /var/www/metrikcorp.com/public_html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride ALL
    Order allow,deny
    allow from all
    </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 ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    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 192.168.1.10:80>
    ServerAdmin webmaster@localhost
    ServerName admin.metrikcorp.com

    DocumentRoot /var/www/admin.metrikcorp.com/public_html
    <Directory />
    Options FollowSymLinks
    AllowOverride All
    </Directory>
    <Directory /var/www/admin.metrikcorp.com/public_html/>
    Options -Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>


    ErrorLog ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    </VirtualHost>

    this is what i get when i reload apache.
    did i put it in wrong?


    Output of config test was:
    AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/apache2/sites-enabled/000-default.conf:1
    AH00112: Warning: DocumentRoot [/var/www/admin.metrikcorp.com/public_html] does not exist
    AH00526: Syntax error on line 53 of /etc/apache2/sites-enabled/000-default.conf:
    Either all Options must start with + or -, or no Option may.
    Action 'configtest' failed.

    Thanks!
     
    Metrik, Mar 3, 2014 IP