Saturday, December 10, 2016

Linux Interview Question - Apache

 Q- How to check the version of Apache server ?
Ans :- rpm -qa |grep httpd

Q: – What is DocumentRoot ?
it is a location of files which are accessible by clients. By default, the Apache HTTP server  is configured to serve files from the /var/www/html/ directory.

Q: – On which port Apache server works ?
http – port 80
https – port 443
The port 80 is a regular port while port 443 is a secure port.

Q: – Tell me name of main configuration file of Apache server ?
httpd.conf

Q: – On which version of apache you have worked ?
httpd-2.2.3
httpd-2.4.16 ---- latest version 

Q: – What do you mean by a valid ServerName directive?
The DNS system is used to associate IP addresses with domain names. The value of ServerName is returned when the server generates a URL. If you are using a certain domain name, you must make sure that it is included in your DNS system and will be available to clients visiting your site.

Q: – What is the main difference between <Location> and <Directory> sections?
Directory sections refer to file system objects; Location sections refer to elements in the address bar of the Web page

Q: – What is the difference between a restart and a graceful restart of a web server?
During a normal restart, the server is stopped and then started, causing some requests to be lost. A graceful restart allows Apache children to continue to serve their current requests until they can be replaced with children running the new configuration.

Q: – What is the use of mod_perl module?
mod_perl scripting module to allow better Perl script performance and easy integration with the Web server.

Q: – If you have added “loglevel Debug” in httpd.conf file, than what will happen?
It will give you more information in the error log in order to debug a problem.

Q: – Can you record the MAC (hardware) address of clients that access your server.
No

Q: – If you have only one IP address, but you want to host two web sites on your server. What will you do?
In this case I will use Name Based Virtual hosting.
ServerName 10.111.203.25
NameVirtualHost *:80
<VirtualHost *:80>
ServerName web1.test.com
DocumentRoot /var/www/html/web1
</VirtualHost>
<VirtualHost *:80>
ServerName web2.test2.com
DocumentRoot /var/www/html/web2
</VirtualHost>

Q: – Can I serve content out of a directory other than the DocumentRoot directory?
Yes, by using “Alias” we can do this.

Q: – If you have to more than one URL map to the same directory but you don't have multiple Alias directives. What you will do?
In this case I will use “AliasMatch” directives.
The AliasMatch directive allows you to use regular expressions to match arbitrary patterns in URLs and map anything matching the pattern to the desired URL.

Q: – Can you record all the cookies sent to your server by clients in Web Server logs?
Yes, add following lines in httpd.conf file.
CustomLog logs/cookies_in.log "%{UNIQUE_ID}e %{Cookie}i" CustomLog logs/cookies2_in.log "%{UNIQUE_ID}e %{Cookie2}i"

Q: – Can we do automatically roll over the Apache logs at specific times without having to shut down and restart the server?
Yes,  Use CustomLog and the rotatelogs programs
Add following line in httpd.conf file.
CustomLog "| /path/to/rotatelogs/path/to/logs/access_log.%Y-%m-%d 86400" combined

Q: – What we can do to find out how people are reaching your site?
Add the following effector to your activity log format. %{Referer}

Q: – How you will put a limit on uploads on your web server?
This can be achieved by LimitRequestBody directive.
<Directory "/var/www/html/data_uploads">
LimitRequestBody 100000
</Directory>
Here I have put limit of 100000 Bytes

Q: – I want to stop people using my site by Proxy server. Is it possible?
<Directory proxy:http://www.test.com/myfiles>
Order Allow,Deny
Deny from all
Satisfy All
</Directory>

Q: – What is mod_evasive module?
mod_evasive is a third-party module that performs one simple task, and performs it very well. It detects when your site is receiving a Denial of Service (DoS) attack, and it prevents that attack from doing as much damage. mod_evasive detects when a single client is making multiple requests in a short period of time, and denies further requests from that client. The period for which the ban is in place can be very short, because it just gets renewed the next time a request is detected from that same host.

Q: – If Some One want Apache server should handle multiple requests over a single TCP connection. Which of the following would allow to do this?
Ans: KeepAlive

Q: -Which of the following HTTP headers will direct a browser towww.nextstep4it.com after waiting five seconds?
Ans: Refresh 5; URL = http://www.nextstep4it.com/

Q: -Cookies can be used by Apache to create a click stream log of user activity. However, for the cookies to work, Apache must be compiled with the _______ module, then the ______ directive must be
Ans:  mod_usertrack; Cookie Tracking on

Q: – Which of the following are TRUE regarding contains in httpd.conf? (Choose two.)
Ans:  . Containers consist of a Paired set of delimiters.
          . Containers allow individual virtual hosts to have their own settings.

Q: -Which of the following best explains why Apache Web servers are able to handles multiple requests?
Ans : B. Apache is able to spawn child processes that handle requests before they die.

Q: – Consider the file "test.html". Which of the following best describes what code does?
Ans: . When the user clicks on "set cookie," thefirst_name cookie is set to "Fred." The first_name cookie can be displayed by clicking the "display cookie" button.

Q: Briefly explain Apache Web Server.
Apache Web Server is one of the most secure, powerful and popular open source HTTP Servers. It can be used to host anything from personal web sites to corporate domains.

Q: You see "connection reset by peer" in error log. What could be the reason for this?
If the end user terminates the connection when the server response was being formed or was being transferred, we see "connection reset by peer" in the error log.

Q: What type of IP is required for Apache Web Server to host our website?
If we have a DSL connection with a static IP then we can use the Apache web server to host our website.

Q: While installing Apache HTTP server, do we need SSL and PHP support?
Yes, SSL and PHP support is required to install Apache HTTP server.

Q: What is virtual hosting?
Virtual hosting is a method for hosting multiple domain names on a server using a single IP address. Virtual hosting allows one server to share its resources, such as memory and processor cycles, in order to use its resources more efficiently.

Q: Is there any size limit for URL rewriting and aliasing in Apache web server?
Apache has no fixed limit on the numbers of Aliases and Redirects which may be declared in the config files.

Q Create a new user file and add a user with username "test" and password "test".
htpasswd -c /usr/local/etc/httpd/users test
User will be prompted to provide the password. The -c argument tells htpasswd to create new file for users. To add more users, -c argument can be omitted.

Q: You need to install Apache web server on Ubuntu server. How can you download and install the Apache2 package?
sudo apt-get install Apache2
OR
sudo aptitude install Apache2
aptitude is known to sort out program dependencies in a better way.

Q: What is the query to install update package of Apache server?
sudo aptitude update
sudo aptitude install Apache2

Q: Towards the end of the install, you may get a warning message during starting of the Apache process because domain name is not configured yet. What could that be?
Apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Q: – What is location of log files for Apache server ?
Ans- /var/log/httpd

Q: – What are the types of virtual hosts ?
a. name-based
b. IP-based.
Name-based virtual host means that multiple names are running on each IP address.
IP-based virtual host means that a different IP address exists for each website served. Most configurations are named-based because it only requires one IP address.

Q: – Command to restart/start Apache web server ?
Ans- service httpd restart/start

Q: – Comamnd to check the conf file  of Apache server ?
httpd   -S
rpm –qc |grep httpd

Q: – What is meaning of “Listen” in httpd.conffile ?
Ans- Port number on which to listen for nonsecure (http) transfers.

Q: – How t to enable PHP scripts on your server?
Ans- If you have mod_php installed, use AddHandler to map .php and .phtml files to the PHP handler. AddHandler application/x-httpd-php .phtml .php

Q: – Which tool you have used for Apache benchmarking?
ab (Apache bench)
ab -n 1000 -c 10 http://www.test.com/test.html

Q: – Can we cache files which are viewed frequently?
Ans- Yes we can do it by using mod_file_cache module.
CacheFile /www/htdocs/index.html

Q : how optimize apache web site or URL
Ans : used memcache server  ???????

Q : How to add module in Apache server

Q : Explain Reverse proxy and why are used

Q : how to add PHP madule in apache

Q : Apache symtex check
httpd  -t

Q : we have 7 web server and my URL is not open, how to troubleshoot from client pc
Ans : add host entry in local pc, check hit URL and check logs
Ans : check server logs

Q : how to install gzip and groupzip  in apache

Q : which language used in apache code

Q : Apache and Nginix deference
  

Q : Specify the Port Number
LDAP - 389
DNS - 53
DHCP - 67,68
HTTP - 80
HTTPS - 443
SMTP - 25
POP3 - 110
FTP - 21,20
Telnet  23
Tomcat  8080, 8007-ajp12, 8009-ajp13,8005-shutdown
NFS  2049
Samba  167/169/445
Redies   6379
HAProxy  8080
SFTP   22
SSH  22
Squid  3128
SVN  3690
POP3 – 110
IMAP – 143
Mysql 3306 ( version 5.5)
  
Q : Apache's features to manipulate URL's

Often in the live of a webmaster it happens, that you want to map an old URL into a new one. The possibilities to manipulate an URL are:

o             Redirect the URL
o             Rewrite the URL
o             Proxy and ReverseProxy Server

Redirection

The Redirect directive maps an old URL into a new one. The new URL is returned to the client which attempts to fetch it again with the new address. One disadvantage is, that the manipulated URL will be displayed in the client browser. Suppose, you want to redirect each request to another Server on the Internet, you specify the following directive in http.conf


Each request to your server will be redirected to http://www.foobar.com.

Rewrite Module

The Apache Module mod_rewrite, is the Swiss Army Knife of URL manipulation, it is a really sophisticated module which provides a powerful way to do URL manipulations like:

o             Solve Trailing Slash Problem
o             Solve Moved DocumentRoot Problem
o             Solve Moved Homedirs to Different Webserver Problem
o             Solve FilesystemReorganisation Problem
o             Redirect Homedirs For Foreigners
o             Redirect Failing URLs To Other Webserver
o             From Old to New (intern)
o             From Old to New (extern)
o             Search pages in more than one directory
o             .... and many more ....

Example:

Map the non SSL URL http://www.foobar.com/abc to the SSL URL https://www.foobar.com/abc

<VirtualHost _default_:80>
  RewriteEngine on
  RewriteRule ^/abc/(.*)$ https://%{SERVER_NAME}/abc/$1 [R,L]
</VirtualHost>
  
Proxy Module

Apache Proxy allows remote servers to be mapped into the space of the local server; the local appears to be a mirror of the remote server. The following proxy directives. In the following example the website Arkum.ch is a proxy for Akadia.ch.
#
# Virtual Host for arkum.ch
#
  <VirtualHost 193.247.121.196>
  ServerAdmin martin dot zahn at akadia dot ch
  ServerName www.arkum.ch
  ProxyRequests On
  ProxyPass / http://www.akadia.ch/
  ProxyPassReverse / http://www.akadia.ch/
</VirtualHost>

ProxyPass

The directive ProxyPass allows remote servers to be mapped into the space of the local server; the local server does not act as a proxy in the conventional sense, but appears to be a mirror of the remote server.

Suppose the local server has address http://wibble.org/; then
  
ProxyPass /mirror/foo/ http://foo.com/

will cause a local request for the <http://wibble.org/mirror/foo/bar> to be internally converted into a proxy request to <http://foo.com/bar>.

ProxyPassReverse

The directive  ProxyPassReverse lets Apache adjust the URL in the Locationheader on HTTP redirect responses. For instance this is essential when Apache is used as a reverse proxy to avoid by-passing the reverse proxy because of HTTP redirects on the backend servers which stay behind the reverse proxy.

Suppose the local server has address http://wibble.org/; then

   ProxyPass /mirror/foo/ http://foo.com/
   ProxyPassReverse  /mirror/foo/ http://foo.com/

will not only cause a local request for the <http://wibble.org/mirror/foo/bar>to be internally converted into a proxy request to <http://foo.com/bar> (the functionality ProxyPass provides here). It also takes care of redirects the server foo.com sends: when http://foo.com/bar is redirected by him tohttp://foo.com/quux Apache adjusts this tohttp://wibble.org/mirror/foo/quux before forwarding the HTTP redirect response to the client.

Dataflow between HTTP-Client and HTTP-Server

Redirect and Rewrite

1.            The HTTP client sends a request to the HTTP Server.
2.            The HTTP Server sends the manipulated URL back to the Client.
3.            The HTTP client sends again a request using the changed URL. If the new URL points to a new HTTP Server, the request a new connection is setup to this server.
4.            The new server sends back the the answer.

One disadvantage using this approach together with another server is, that the manipulated URL is not hidden from the HTTP client, the changed URL is presented to the users.
  
 Proxy Server

1.            The HTTP client sends a request to the HTTP Proxy.
2.            The HTTP Proxy connects the HTTP Server.
3.            The HTTP Server sends back the answer to the HTTP Proxy.
4.            The HTTP Proxy sends back this answer to the HTTP client.

There are several advantages using proxies. The new server is completely hidden for the user. The URL always points to the HTTP Proxy, the connection to the real HTTP Server is hidden. The HTTP Proxy caches the documents locally, therefore we have  a performance gain.



Q : My clients are getting services from servers but how to know which client is using which service. is there any files to keep information about these? Clients used ftp, nis, samba, apache, squid, nfs and mail services how to know how many users got service from server side with date, time and client system ip?

Mail server – /var/log/mail/maillog [RedHat,centos]
ssh – /var/log/secure
Apache – /var/log/http/access.log
nfs – /var/lib/nfs/rmtab


Q. check log format and location
/var/log/httpd/
CustomLog "| /path/to/rotatelogs/path/to/logs/access_log.%Y-%m-%d 86400" combined
% -----hostname
Y ----- year
m ----- month
d -------- date
combined   --- log format templates
common ---log format templates
agent ---------log format templates

Q :- Apache error code, 500, 400, 403, 404, 303
404 error  ----- document root, path not found
400 -------
403 -------   forbiturn (permission, allow /deny )
500 ------madules issue (internal server error) miss configuration of modules, apache syntax error-pass error
300 -----  redirection issue                              
100  -----  request completed 
200  ----- client and server request service completed
  
Q. how to copy single word in linux
Used ye????   yye….
^ ----start
$-----end

Q. web site not opening, all contains ok

Clear browser history and check

No comments:

Post a Comment