Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 6: Web Servers — Nginx and Apache

Interview Questions

These questions on web servers definitely come up in cloud and DevOps interviews. When you reply, say one command or path out loud – the interviewer sees your hands-on experience.

Q1. What is the difference between Nginx and Apache?
Nginx is event-driven and asynchronous, very efficient for static content and reverse proxying. Apache uses process/thread-based MPMs, has many modules and supports per-directory .htaccess files.
Q2. What is a reverse proxy?
A server that receives client requests and forwards them to backend servers/apps (e.g. Node on 127.0.0.1:3000), then returns the response. It provides TLS termination, caching, load balancing and security.
Q3. How do you test Nginx configuration before applying it?
sudo nginx -t, then sudo service nginx reload if the test passes.
Q4. What do HTTP 403, 404 and 502 mean?
403 Forbidden (permission/SELinux/no index), 404 Not Found (wrong path/root), 502 Bad Gateway (the upstream app behind the proxy is down or unreachable).
Q5. What is SELinux and how do you fix a web-content label issue?
Security-Enhanced Linux, a mandatory access control system on RHEL/CentOS. Fix labels with sudo restorecon -Rv /var/www/site (or semanage fcontext for custom paths).
Q6. What is .htaccess and why doesn't Nginx support it?
A per-directory Apache config file read on every request. Nginx avoids it for performance; all configuration lives in central files.

More interview questions, across stacks

Q. Where does Tomcat fit compared with nginx?
Tomcat runs Java web applications (servlets, WAR files). nginx usually sits in front for TLS, static files and load balancing, and proxies to Tomcat on 8080.

Q. Why put nginx in front of Gunicorn, PM2 or Kestrel?
For TLS, static file serving, buffering slow clients, rate limits and a single public port (443). The app server then listens only on 127.0.0.1.

Q. What is the difference between reload and restart?
Reload re-reads the config without dropping connections, and nginx refuses to apply a broken config. Restart stops and starts the process, which drops connections.

Q. How do you hide the server version?
nginx: server_tokens off;. Apache: ServerTokens Prod and ServerSignature Off. Check the Server: header with curl -I.

Q. What does HTTP 504 mean?
Gateway timeout. The proxy reached the app but the app did not answer in time. This often means a slow database query or a stuck worker.

Q. What is the cloud equivalent of nginx in front of many servers?
A load balancer: AWS Application Load Balancer, Azure Application Gateway or Google Cloud Load Balancing.

Tip. Back each answer with a real command or file path. Interviewers at companies like TCS, Infosys and Accenture often ask "show me how you would check that".

Q. How do you find which program is using port 80?
sudo ss -tlnp | grep :80 shows the process name and PID.

Q. Where are the nginx logs on Amazon Linux?
/var/log/nginx/access.log and error.log.

Q. What is .htaccess and why is it slower?
Per-directory Apache config that is read on every request. nginx has no equivalent because all config is loaded once at startup.

Q. What is a default server?
The block that answers when no server_name matches the Host header.

Scenario question (common at product companies like Flipkart): "Users see 502 after a deploy. Walk me through it." Answer: check the app process, then curl the app locally, then the nginx upstream settings, then the logs. Name the commands for your stack (pm2, systemctl, journalctl).

Key terms

  • Web server: Serves files and proxies apps: nginx, Apache.
  • Application server: Runs code: PHP-FPM, Gunicorn, PM2, Tomcat, Kestrel.
  • Reverse proxy: Receives requests and forwards them to an app.
  • Status 403: Forbidden: permissions, SELinux or no index file.
  • Status 502: Bad gateway: the app behind the proxy is down.
  • SELinux: Mandatory access control on RHEL-family systems.

Mini case study

Suppose we are a junior cloud engineer at a Bengaluru e-commerce startup (sample data). The team runs a PHP admin, a Node.js storefront API and a Python report job on two EC2 instances. Using this chapter, you write a one-page runbook: which service listens where, how to test and reload each one, which logs to read, and which ports are public (only 80 and 443, plus 22 from the office IP). New team members can then fix most problems on their own.