0
0
Nginxdevops~10 mins

Web server vs application server in Nginx - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Process Flow - Web server vs application server
Client sends HTTP request
Web Server receives request
Static content
Serve file
Application Server processes
Response sent back to Web Server
Web Server sends response to Client
The client sends a request to the web server. The web server serves static files directly or forwards dynamic requests to the application server, which processes them and returns a response.
Execution Sample
Nginx
server {
  listen 80;
  location / {
    root /var/www/html;
    index index.html;
  }
  location /app/ {
    proxy_pass http://localhost:8080;
  }
}
Nginx configuration serving static files from /var/www/html and forwarding /app/ requests to an application server on port 8080.
Process Table
StepRequest URLWeb Server ActionApplication Server ActionResponse Sent
1/index.htmlServe static file /var/www/html/index.htmlN/AStatic HTML content
2/app/dataForward request to app server at localhost:8080Process dynamic request, generate JSONJSON response
3/about.htmlServe static file /var/www/html/about.htmlN/AStatic HTML content
4/app/loginForward request to app server at localhost:8080Process login, generate session tokenSession token response
5/favicon.icoServe static file /var/www/html/favicon.icoN/AIcon file content
💡 All requests handled either by serving static files or forwarding to application server for dynamic content.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5
Request URLN/A/index.html/app/data/about.html/app/login/favicon.ico
Web Server ActionN/AServe static fileForward to app serverServe static fileForward to app serverServe static file
Application Server ActionN/AN/AProcess dynamic requestN/AProcess loginN/A
Response SentN/AStatic HTMLJSON responseStatic HTMLSession tokenIcon file
Key Moments - 3 Insights
Why does the web server forward some requests to the application server?
Because those requests need dynamic processing which the web server alone cannot do, as shown in execution_table rows 2 and 4.
Can the web server serve dynamic content by itself?
No, the web server serves static files directly but forwards dynamic requests to the application server, as seen in the execution_table where only static URLs are served directly.
What happens if a request is for a static file?
The web server serves the file directly without involving the application server, as shown in execution_table rows 1, 3, and 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what action does the web server take for the request '/app/data'?
AServe static file
BForward request to application server
CReturn 404 error
DCache the response
💡 Hint
Check the 'Web Server Action' column for step 2 in the execution_table.
At which step does the application server generate a session token?
AStep 4
BStep 3
CStep 1
DStep 5
💡 Hint
Look at the 'Application Server Action' column for step 4 in the execution_table.
If the web server did not forward '/app/login' requests, what would happen?
AStatic login page would be served
BApplication server would still process the request
CRequest would fail or return an error
DRequest would be cached
💡 Hint
Refer to the concept_flow and execution_table showing forwarding is needed for dynamic content.
Concept Snapshot
Web server handles HTTP requests.
Serves static files directly.
Forwards dynamic requests to application server.
Application server processes logic and returns response.
Nginx example: static content served from root, dynamic proxied to app server.
Full Transcript
When a client sends a request, the web server first checks if it is for static content like HTML or images. If yes, it serves the file directly. If the request is for dynamic content, such as data or login, the web server forwards it to the application server. The application server processes the request, runs any needed code, and sends back a response. The web server then sends this response to the client. This separation helps handle static and dynamic content efficiently.