1

I am familiar with running nginx as proxy server but I am having hard time to put things together using openshift. I have nodejs app and want to use using nginx as proxy server. This is my nginx conf file. Should I replace server_name with service? is there other way to achieve this in openshift?

upstream myapp {
    server 127.0.0.1:8080;
    keepalive 8;
}

# the nginx server instance
server {
    listen 0.0.0.0:80;
    server_name x.x.x.x;
    access_log /var/log/nginx/my-app.com.log;

    location / {
      autoindex on;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://myapp/;
      proxy_redirect off;
    }
 }
user557657
  • 856
  • 1
  • 12
  • 35

1 Answers1

1

Your guess is correct, you need to refer to the service by its name. If the service isn't in the default namespace you need to use the Fully Qualified Domain Name:

<svc-name>.<namespace>.svc.cluster.local

Instead of hardcoding this configuration into the container, the proper way is to apply it as a configmap to the cluster and mount it as a volume into the specified path for nginx pod.

Rinor
  • 1,790
  • 13
  • 22
  • in my case I am not seeing cluster.local. All I see service name is as `..svc` – user557657 Oct 01 '19 at 16:24
  • I am not sure where are you looking for the cluster.local? Please see the following documentation: https://docs.openshift.com/enterprise/3.0/architecture/additional_concepts/networking.html When you create a pod you have to specify a namespace (same for the service) if you don't specify a namespace it picks the currently active namespace (usually default). Let's say that you named the nodejs service `nodejs` and you didn't specify any namespace (resolving into the default ns) this means that the FQDN for your service is `nodejs.default.svc.cluster.local`. Give it a try ;) – Rinor Oct 01 '19 at 16:34
  • just confirming - nodejs.default.svc.cluster.local will go in upstream block? `upstream myapp { server nodejs.default.svc.cluster.local:8080; keepalive 8; }` – user557657 Oct 01 '19 at 17:19
  • Are these containers both started within one pod? or are they in separate pods? – Rinor Oct 01 '19 at 17:20
  • do you have a service for your app and what is it named? – Rinor Oct 01 '19 at 17:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/200250/discussion-between-rinormaloku-and-user557657). – Rinor Oct 01 '19 at 17:32
  • `NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx-custom ClusterIP 172.0.x.x 80/TCP 4m s2i-nodejs-container ClusterIP 172.0.x.x 8080/TCP 1d` – user557657 Oct 01 '19 at 17:33