3

I am using docker compose for running nginx with latest version, using the volumes i am copying the nginx.conf files into nginx docker container

  nginx:
    image: nginx:1.20
    container_name: nginx
    ports:
      - 80:80  
    restart: unless-stopped
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/default.conf
    depends_on:
      - strapi
      - rocketchat
      - keycloak
    networks:
      - test-network

Every applications are running on a same Network.

Here is the nginx.conf file

events {
  worker_connections  4096;  ## Default: 1024
}
http {
 server {
   listen 80;

   server_name qa.xxx.com;

   location / {
       proxy_pass http://strapi-container:1337/;
   }

   location /chat {
       proxy_pass http://rocketchat-container:3000;

   }

   location /auth {
       proxy_pass http://keycloak-container:8080;
       proxy_set_header Host $host;
   }
 }
}

My intention is to run the three backend URL /, /chat, /auth with nginx configurations. When running the application on instance, http://ip-address/chat, http://ip-address/auth doesn't seems to work

Here is the nginx log error

2021/06/02 07:46:42 [error] 31#31: *1 open() "/usr/share/nginx/html/chat" failed (2: No such file or directory), client: 115.96.103.237, server: localhost, request: "GET /chat HTTP/1.1", host: "310.28.67.222"
115.96.103.237 - - [02/Jun/2021:07:46:42 +0000] "GET /chat HTTP/1.1" 404 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" "-"
2021/06/02 07:46:50 [error] 31#31: *2 open() "/usr/share/nginx/html/auth" failed (2: No such file or directory), client: 115.96.103.237, server: localhost, request: "GET /auth HTTP/1.1", host: "310.28.67.222"
115.96.103.237 - - [02/Jun/2021:07:46:50 +0000] "GET /auth HTTP/1.1" 404 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" "-"
klee
  • 1,554
  • 2
  • 19
  • 31
  • 1
    Use `nginx -T` (uppercase `T`) to view the entire configuration across all included files. The error message is not consistent with the configuration file you have posted. The error corresponds to `server_name localhost` and **not** `server_name qa.xxx.com`. – Richard Smith Jun 02 '21 at 09:37

1 Answers1

0

Try trailing slashes behind the proxy_pass, unless you want to have the folder added.

 location /chat {
       proxy_pass http://rocketchat-cnr:3000;
   }

redirects to http://rocketchat-cnr:3000/chat, while

 location /chat {
       proxy_pass http://rocketchat-cnr:3000/;
   }

redirects to http://rocketchat-cnr:3000/

Visit http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass for more Info

araisch
  • 1,727
  • 4
  • 15
  • i have added the trailing slashes and executed but http://ip-address/chat doesn't work. – klee Jun 02 '21 at 10:15
  • Post full compose please – araisch Jun 02 '21 at 12:16
  • If someone makes a request using an IP address instead of a server name, the “Host” request header field will contain the IP address and the request can be handled using the IP address as the server name: server { listen 80; server_name example.org www.example.org "" 192.168.1.1 ; ... } http://nginx.org/en/docs/http/server_names.html – araisch Jun 02 '21 at 13:02
  • @arsisch Thanks, It worked after overwriting the nginx default configurations – klee Jun 02 '21 at 16:51