Linux Nginx As Reverse Proxy Task

Make sure that you nginx config knows were static content is root /var/www/html

Hi @Chudo, @devops503 , @kodekloud-support3
I may be facing a similar issue , can you please help .

The apache server is supposed to run on port 6000 and nginx on 8095 .
httpd.conf was updated :

Listen 6000

default nginx.conf updated server section as follows :

    server {
        listen       8095  default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

    }

And i created a proxy.conf in /etc/nginx/conf.d/ as below

server {
 listen 8095;
 server_name 172.16.238.16;
 root /var/www/html;
}

location / {
    proxy_pass http://localhost:6000;
}

So i have set the root to point to apache root /var/www/html in proxy.conf .
I am encountering 2 issues :

  1. Getting 403 Forbidden Error . When i checked the error.log , it states that access to nginx root /usr/share/nginx/html is Forbidden
  2. nginx is not pointing to apache root /var/ww/html specified in proxy.conf . It points to the default root in the nginx.conf file

Hi Antony

/etc/nginx/nginx.conf
user nginx; => user apache; make Nginx work under this user

server {
listen 8095 default;
server_name 172.16.238.16;
}

location / {
root /var/www/html; => Move the root line to location section

}

Thank you @devops503 , will try your changes

Hi @devops503 , are these changes to be done all in the /etc/nginx/nginx.conf file ?

Yes,

The changes on nginx.conf

/etc/nginx/nginx.conf

user nginx; => user apache; make Nginx work under this user

server {
listen 8095 default;
server_name 172.16.238.16;
}

location / {
root /var/www/html; => Move the root line to location section
proxy_pass http://127.0.0.1:6000/;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr
}

All necessary settings for proxing
/etc/nginx/conf.d/proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10 m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

1 Like

Thank you @devops503 , that worked !!

kindly help i am not able to install nginx.
and please provide me further steps to complete the task.
Thanks


@antonysavio1111 @devops5032 @sanyamc230493 @kiran

Hi , you need to install epel-release before you can install nginx ,ie,
yum install epel-release -y
yum install nginx -y

For the main setup , follow the steps mentioned in the topic

Thank you @antonysavio1111 Completed the Task Successfully.

@devops503…For this task I installed apache first and the did changes in conf file and changed the port as mentioned in the problem statement…and the installed nginx and followed the steps you mentioned…but after starting nginx …getting the error…Also , in nginx status i checked… something is wrong with the conf file…plz advice what i am doing wrong/…

Can anyone plz suggest …what did i do wrong in configuration file…

nginx -t with the help of this command you can config error in nginx config file

Edit the file and change below parameters according to your question.
listen 8096;
listen [::]:8096;
server_name 172.16.238.16;
Under location tab, add below line
proxy_pass http://172.16.238.16:8082

Is it 5000 proxy_pass http://127.0.0.1:5000/; your Apache port ??

After running
systemctl start nginx
Run
journalctl -xe | grep emerg
To get exactly what the problem is

I am having the same issues, any input here guys ??

any luck with this ?

@Ayman, @kodekloud-support3 Same my task is failed, but as per result I done correctly everything.

As per my understanding of the question, reverse proxy is configured successfully and both nginx and apache servers are running.

Hello Devops503/Everyone,

Can you please help me in resloving nginx reverse proxy task.Please correct me where am doing wrong my nginx config file,proxy file and the error

Thanks
Sree

@sreedhar I see there is a syntax error with the setting “client_max_body_size”. The value is “10 m” instead “10m”. Try removing the space and see.

Thanks Salim.Unfortunately task expired ,will try again when i get assigned