Complete the code to specify the port where Nginx listens for HTTP requests.
server {
listen [1];
server_name localhost;
}The default port for HTTP traffic in Nginx is 80. This is where the web server listens for incoming requests.
Complete the code to forward requests to an application server running on port 3000.
location /app/ {
proxy_pass http://127.0.0.1:[1]/;
}The application server is running on port 3000, so Nginx forwards requests to that port.
Fix the error in the proxy_pass directive to correctly forward to the app server.
location /api/ {
proxy_pass http://127.0.0.1[1]3000/;
}The proxy_pass URL must have a colon ':' before the port number to specify the port.
Complete the code to set up a reverse proxy with caching for the app server.
location /service/ {
proxy_pass http://127.0.0.1:3000/;
proxy_cache [1];
}Use ':' before the port number and specify the cache zone name 'my_cache' for proxy_cache.
Fill both blanks to configure Nginx to serve static files and proxy API requests.
server {
listen 80;
location /static/ {
root [1];
}
location /api/ {
proxy_pass http://127.0.0.1:3000/;
proxy_set_header Host [2];
}
}Static files are served from '/var/www/html'. The proxy_pass needs ':' before port 3000. The Host header is set to '$host' to pass the original host.