Linux Nginx As Reverse Proxy Task

Dear @Inderpreet @kodekloud-support3

I have verified the index.html file from the jump host on the backup server is the same but the validation is telling me that I have copied the wrong file. Why? Please check.

Thanks.

1 Like

Me too

Hi @Inderpreet

can you please check
Same error

@Salim @oussama.smairkandi @kiran

Sorry for this inconvenience, this happened due to some maintenance we are doing. I am marking this task as Success for you guys.

3 Likes

@Inderpreet Thanks for taking this point too quickly

I also got the same error and my task got failed
@Inderpreet @kodekloud-support3

image

@sanyamc230493 According to your config your Nginx and Apache are using different document roots . /var/www for Nginx and /var/www/html for Apache, why so ?
Actually you need not to define root for Nginx since it will server what Apache has.

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;

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