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!
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 ...
}