10

I am totally new to Nginx and need your help. Basically I have a single server with single IP address, but I want to host two different web application within the server with different domain name. So, basically, for each domain name, I want it to redirect to different port number. I tried below and got an error

[root@mysvr nginx]# nginx -t -c /etc/nginx/nginx.conf
nginx: [emerg] "proxy_pass" directive is not allowed here in /etc/nginx/nginx.conf:41
nginx: configuration file /etc/nginx/nginx.conf test failed

Following is the Nginx setting. Line 41 is where the proxy_pass is.

server {
  listen 80;
  server_name server1.com www.server1.com;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://127.0.0.1:1003;
}

server {  
  listen 80;
  server_name server2.com www.server2.com;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://192.168.1.1:1004;
}

Thank you!

1 Answer 1

15

If you check the docs for proxy_pass, proxy_pass needs to be in a location, if in location or limit_except block. You have it in a server block.

Try replacing your usage of proxy_pass with

location / {
    proxy_pass ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.