Nginx as reverse proxy and apache setup - help

Hi team,

I have a task to to install apache and nginx and run them on some respective ports

For apache I have changed port no. in /etc/httpd/conf/httpd.conf location but unable to change port for nginx.

I’m confused when to use /etc/nginx/nginx.conf and when to create default.conf file in /etc/ngnix/conf.d/ location.

settings of nginx as a reverse proxy help
while creating default.conf file in /etc/ngnix/conf.d/ location which lines are needed to be added to the file, I have read some articles but didn’t get why do they use above code while we add apache as reverse proxy

 proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8080;

please help me as I am a begineer :pray: :pray:

[gone through this link ] (https://www.hugeserver.com/kb/configure-nginx-reverse-proxy-apache-centos/)

@KodeKloud @player001 @kodekloud-support3

@player001 – read your many posts which gave me hint to solve my issues please help me :pray

Please post your task.
It will help to understand what exactly wants to do.

hi @AkshayT and all other friends
@KodeKloud @kodekloud-support3 @player001 @Inderpreet

please find screenshot of my task

apache installed and configured to 5003

Please help me with the task

hi @AkshayT and all other friends
@KodeKloud @kodekloud-support3 @player001 @Inderpreet

nginx is installed and set to port 8096 in /etc/nginx/nginx.conf

(but not sure where to edit it whether to edit in /etc/nginx/nginx.conf or to create a file in /etc/nginx/conf.d/filename.conf )

and please help to set nginx as reverse proxy

nginx port no. and document root is changed as shown in above screenshot

Hi Shubham,

First you need to install apache
yum install httpd
Configure it on port as given in Q.
For that you need to change /etc/httpd/conf/httpd.conf file and edit listen parameter.
Restart the httpd service.

For nginx, you need to install nginx on server using,
yum install epel-release
yum install nginx

then you need to configure some parameter in nginx.conf located at /etc/nginx
Edit the file and change below parameters according to your question.
listen 80996;
listen [::]:8096;
server_name 172.16.238.16;
Under location tab, add below line
proxy_pass http://72.16.238.16:5003

Start the nginx service.
Check the web page by using curl command

Please make sure before submitting task you have completed all the sub questions asked in task.

hi @AkshayT,

thanks for response and help

i have some questions please help me out here

should i create file proxy.conf in /etc/ngnix/conf.d/proxy.conf

and what lines should be added int that file ???

No.
Not need to create proxy.conf file anywhere.
Just change the nginx.conf file.

@AkshayT

should i add root as /var/www/html/ under location before adding proxy pass ??

Keep it as default.
Don’t change anything.
Make only that changes as I mentioned.
Hope it will help you.

hi @AkshayT

thanks for help my task completed successfully

forget to take screenshot of task completed

Amazing…
Keep continue your work.


@AkshayT @shubham-beginner…I followed the above steps…while changing nginx.conf file , i am getting the error…plz suggest…what i am doing wrong

Hello, pratikshag
Can you check the output of journalctl -xe -u nginx. It’s look like you have done something wrong in the configuration of nginx.
Check the port of nginx which one is assigned. It’s opted by nginx service or other’s service. (netstat command)

@player001…I am doing some mistake in nginx.conf file(in location section)…If i removed pass proxy from location its not giving error…plz check…I am attaching the screenshot…

Hello, pratikshag

location / {
proxy_pass http://72.16.238.16:6300
}

You need to define a DocumentRoot path instead of proxy_pass and you wrote incorrect IP addr as well.

I corrected the ip address…but still giving error…Can you pls tell me what exactly should be added in nginx.conf fille.

Now i able to restart the nginx service , but while copying the index.html file,its giving error.

, Even i changed the permissions of both source an destination folder.

You can copy in the /tmp directory in the target machine then shift the files into the destination directory.