Apache Redirects

Ticker

6/recent/ticker-posts

Apache Redirects

Question: The Nautilus devops team got some requirements related to some Apache config changes. They need to setup some redirects for some URLs. There might be some more changes need to be done. Below you can find more details regarding that:

httpd is already installed on app server 2. Configure Apache to listen on port 5003.

Configure Apache to add some redirects as mentioned below:

a.) Redirect http://stapp02.stratos.xfusioncorp.com:<Port>/ to http://www.stapp02.stratos.xfusioncorp.com:<Port>/ i.e non www to www. This must be a permanent redirect i.e 301

b.) Redirect http://www.stapp02.stratos.xfusioncorp.com:<Port>/blog/ to http://www.stapp02.stratos.xfusioncorp.com:<Port>/news/. This must be a temporary redirect i.e 302.

Please Note:-  Perform the below commands based on your question server,  user name & other details that might differ. 
So please read the task carefully before executing it. 
All the Best 👍

Solution:  

1. Login on   App server as per the task & switch to root user

thor@jump_host ~$ ssh steve@stapp02

The authenticity of host 'stapp02 (172.16.238.11)' can't be established.

ECDSA key fingerprint is SHA256:SySamszyWhhLGFiybhGBqfrr8g55wS/3e37ZpBOvICs.

ECDSA key fingerprint is MD5:6d:31:18:2a:f9:07:f3:29:dd:0a:d3:1f:6e:04:0a:db.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'stapp02,172.16.238.11' (ECDSA) to the list of known hosts.

steve@stapp02's password:

[steve@stapp02 ~]$ sudo su -

 We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

     #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

 [sudo] password for steve:

[root@stapp02 ~]#

2. Confirm the current httpd version & configuration 

[root@stapp02 ~]# rpm -qa |grep httpd

httpd-tools-2.4.6-90.el7.centos.x86_64

httpd-2.4.6-90.el7.centos.x86_64

[root@stapp02 ~]#

[root@stapp02 ~]# cat /etc/httpd/conf/httpd.conf |grep Listen

# Listen: Allows you to bind Apache to specific IP addresses and/or

# Change this to Listen on specific IP addresses as shown below to

#Listen 12.34.56.78:80

Listen 8080

[root@stapp02 ~]#

[root@stapp02 ~]# cat /etc/httpd/conf/httpd.conf |grep redirect

# 1) plain text 2) local redirects 3) external redirects

[root@stapp02 ~]#

3. Edit the configuration & change the port no as per the task 

[root@stapp02 ~]# vi /etc/httpd/conf/httpd.conf

[root@stapp02 ~]# cat /etc/httpd/conf/httpd.conf |grep Listen

# Listen: Allows you to bind Apache to specific IP addresses and/or

# Change this to Listen on specific IP addresses as shown below to

#Listen 12.34.56.78:80

Listen 5003

[root@stapp02 ~]#

4. As per the task we need to redirect permanent & temporary for which will create  main.conf 

[root@stapp02 ~]# ll /etc/httpd/conf.d/

total 20

-rw-r--r-- 1 root root 2926 Aug  8  2019 autoindex.conf

-rw-r--r-- 1 root root 1252 Dec 17  2019 php.conf

-rw-r--r-- 1 root root  366 Aug  8  2019 README

-rw-r--r-- 1 root root 1252 Aug  6  2019 userdir.conf

-rw-r--r-- 1 root root  824 Aug  6  2019 welcome.conf

[root@stapp02 ~]#

[root@stapp02 ~]# vi /etc/httpd/conf.d/main.conf

[root@stapp02 ~]# cat  /etc/httpd/conf.d/main.conf

<VirtualHost *:5003>

ServerName stapp02.stratos.xfusioncorp.com

Redirect 301 / http://www.stapp02.stratos.xfusioncorp.com:5003/

</VirtualHost>

 

<VirtualHost *:5003>

ServerName www.stapp02.stratos.xfusioncorp.com:5003/blog/

Redirect 302 /blog/ http://www.stapp02.stratos.xfusioncorp.com:5003/news/

</VirtualHost>

[root@stapp02 ~]#

5. Post file saved restart and check the httpd status 

[root@stapp02 ~]# systemctl restart httpd

[root@stapp02 ~]# systemctl status  httpd

● httpd.service - The Apache HTTP Server

   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)

   Active: active (running) since Mon 2021-07-19 17:13:15 UTC; 8s ago

     Docs: man:httpd(8)

           man:apachectl(8)

  Process: 695 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)

 Main PID: 727 (httpd)

   Status: "Processing requests..."

   CGroup: /docker/fd81a8b1ef8248f7a8bd27930f724b7ee5bd0e034c505b88a97d8091e444ff4d/system.slice/httpd.service

           727 /usr/sbin/httpd -DFOREGROUND

           729 /usr/sbin/httpd -DFOREGROUND

           730 /usr/sbin/httpd -DFOREGROUND

           731 /usr/sbin/httpd -DFOREGROUND

           732 /usr/sbin/httpd -DFOREGROUND

           └─733 /usr/sbin/httpd -DFOREGROUND

 Jul 19 17:13:15 stapp02.stratos.xfusioncorp.com systemd[1]: Starting The Apache HTTP Server...

Jul 19 17:13:15 stapp02.stratos.xfusioncorp.com httpd[727]: AH00558: httpd: Could not reliably determine the server's fully qualifi...ssage

Jul 19 17:13:15 stapp02.stratos.xfusioncorp.com systemd[1]: Started The Apache HTTP Server.

Hint: Some lines were ellipsized, use -l to show in full.

[root@stapp02 ~]#

 

6. Validate the task by Curl 

[root@stapp02 ~]# curl http://stapp02.stratos.xfusioncorp.com:5003/

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>301 Moved Permanently</title>

</head><body>

<h1>Moved Permanently</h1>

<p>The document has moved <a href="http://www.stapp02.stratos.xfusioncorp.com:5003/">here</a>.</p>

</body></html>

[root@stapp02 ~]# curl http://www.stapp02.stratos.xfusioncorp.com:5003

Welcome to the Nautilus Group!

[root@stapp02 ~]#

[root@stapp02 ~]# curl http://www.stapp02.stratos.xfusioncorp.com:5003/blog/

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>302 Found</title>

</head><body>

<h1>Found</h1>

<p>The document has moved <a href="http://www.stapp02.stratos.xfusioncorp.com:5003/news/">here</a>.</p>

</body></html>

[root@stapp02 ~]#

[root@stapp02 ~]# curl http://www.stapp02.stratos.xfusioncorp.com:5003/news/

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

<html><head>

<title>404 Not Found</title>

</head><body>

[root@stapp02 ~]#

8. Click on Finish & Confirm to complete the task successful

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , 

please go through and share your comments. Like and share the knowledge






Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user