Tag Archive: apache


Edit the configuration file:
#  vim  /etc/httpd/conf/httpd.conf
Press ‘shift+g‘ to go at the end of file, and add:

<Directory “/var/www/html”>
AuthType Basic
AuthName “Authorized Users only”
AuthUserFile  /etc/httpd/authpass
Require user user1 user2                     //add all usernames
</Directory>

 

#  htpasswd  -b  /etc/httpd/authpass [username]  [password]

#service httpd restart

http://127.0.0.1 (it will ask for username and password for accessing the website.)

OR edit  “/etc/hosts”, add

127.0.0.1                     http://www.abc.com

Access www.abc.com from browser.

Advertisements

You can create a simple webserver(without SSL) from here.

Create a certificate:

#  cd  /etc/pki/tls/certs

 

Create private key:

#  make  server.key

Enter the passphrase.

Remove passphrase from private key:

#  openssl  rsa  -in  server.key  -out  server.key

 

#  make  server.csr

Enter the relevant information for your certificate.

 

Create certificate:

#  openssl  x509  -in  server.csr  -out  server.crt  -req  -signkey  server.key  -days  365

#  chmod  400  server.*

 

Configure SSL:

 

#  yum  install  mod_ssl

 

#  vi  /etc/httpd/conf.d/ssl.conf

 

Edit line no. 77 & 78:

DocumentRoot            “/var/www/html”

ServerName                http://www.abc.com:443

 

Edit line no. 105:

SSLCertificateFile        /etc/pki/tls/certs/server.crt

 

Edit line no. 112:

SSLCertificateKeyFile              /etc/pki/tls/private/server.key

(Note: Private key is also present in “certs” directory, you can specify that one also or you can copy it in “private” directory.)

 

#  service httpd start

 

Now access https://www.abc.com from browser and install the certificate.(Map server name http://www.abc.com with ip address in “/etc/hosts”)

 

 

Apache Web Server Configuration

First, install the httpd packages :

#  yum  install  httpd*

The main configuration file is httpd.conf which is present in /etc/httpd/conf/,  to edit :

#  vi  /etc/httpd/conf/httpd.conf

Go to the end of file and copy the last 7 lines and paste at the end.

  1. <VirtualHost *:80>
  2. #    ServerAdmin webmaster@dummy-host.example.com
  3. DocumentRoot [location of directory of web pages]
  4. ServerName  [name of site or server]
  5. #    ErrorLog logs/dummy-host.example.com-error_log
  6. #    CustomLog logs/dummy-host.example.com-access_log common
  7. </VirtualHost>

In the 1st line replace the  * with the ip address of server. You can do with the  * also but it will needed when you do the virtual hosting.

In the 3rd line give the path of the directory containing the web pages.

In the 4th line write the name of the site which you want to use.

Leave the other lines as it is.

Now, append the hosts file :

#  vi  /etc/hosts

[server IP]                [name of site or server]

And finally :

# service httpd start

Open your web browser and type the name of site or server.

——–Virtual Hosting———

Again copy and paste those 7 lines :

  1. <VirtualHost [ip address of server]:80>
  2. #    ServerAdmin webmaster@dummy-host.example.com
  3. DocumentRoot [location of directory of web pages]
  4. ServerName  [name of site or server]
  5. #    ErrorLog logs/dummy-host.example.com-error_log
  6. #    CustomLog logs/dummy-host.example.com-access_log common
  7. </VirtualHost>

But this time you must write the IP address of server in the 1st line in place of  *,  rest remains the same.

For virtual hosting to work you have to change one more setting.

#NameVirtualHost  *:80

This line is present 10-12 lines above those 7 lines. You have to uncomment this line and provide server IP address in place of  * .

Append the hosts file again, the IP address remains the same only the name of site is changed.

Reload or restart the httpd service.

Open your web browser and there you go…

Note: DNS server should be configured and service named should be running for website name resolution.