0
0
Nginxdevops~30 mins

Request/response transformation in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Request and Response Transformation with Nginx
📖 Scenario: You are setting up a simple web server using Nginx. You want to transform incoming requests and outgoing responses to meet specific needs.For example, you want to add a custom header to all responses and rewrite certain request URLs.
🎯 Goal: Build an Nginx configuration that rewrites request URLs starting with /oldpath to /newpath, and adds a custom response header X-Custom-Header: DevOpsProject to all responses.
📋 What You'll Learn
Create a basic Nginx server block listening on port 8080
Rewrite requests from /oldpath to /newpath
Add a custom response header X-Custom-Header: DevOpsProject
Serve static files from /usr/share/nginx/html
💡 Why This Matters
🌍 Real World
Web servers often need to modify requests and responses to support legacy URLs, add security headers, or customize content delivery.
💼 Career
Understanding Nginx request and response transformations is essential for DevOps roles managing web infrastructure and improving application delivery.
Progress0 / 4 steps
1
Create a basic Nginx server block
Write an Nginx server block that listens on port 8080 and serves files from /usr/share/nginx/html. Name the server block server and include the listen and root directives.
Nginx
Need a hint?

Use server { ... } block with listen 8080; and root /usr/share/nginx/html;.

2
Add URL rewrite rule
Inside the existing server block, add a location /oldpath block that rewrites requests to /newpath using the rewrite directive with a permanent redirect.
Nginx
Need a hint?

Use location /oldpath { rewrite ^/oldpath(.*)$ /newpath$1 permanent; } inside the server block.

3
Add custom response header
Inside the server block, add the directive add_header X-Custom-Header "DevOpsProject"; to add a custom header to all responses.
Nginx
Need a hint?

Add add_header X-Custom-Header "DevOpsProject"; inside the server block but outside location blocks.

4
Test and display the final configuration
Print the entire Nginx configuration you wrote so far to verify it includes the server block with listen 8080;, root /usr/share/nginx/html;, the location /oldpath rewrite, and the add_header directive.
Nginx
Need a hint?

Print the full configuration text exactly as written.