0

I have several websites running inside docker containers. And since there are several docker containers running on the same server, for each of them a redirection is setup using nginx. Now I want to write a simple shell script to check periodically if the url is available. What I've tried is

echo $(curl mysubhost.com --write-out '%{http_code}' --silent --output /dev/null servername)

Now, because of redirection I always get a result code 301000

Even when the container is stopped, or the apache service inside the container is stopped I always get the same result code because the nginx makes redirection in the layer of the server.

What is the proper way to monitor if my websites are available? One of the way is to check if the containers are running, but that's not enough, since the containers can be up and running but there can be a lot of reasons for the websites to be unavailable.

Nginx proxy looks like

server {

  server_name mysubhost.com www.mysubhost.com;

  location / {
       proxy_pass http://127.0.0.1:100;
      proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
         proxy_ssl_verify              off;

}}

4
  • By "redirection", do you mean a reverse proxy?
    – gronostaj
    Commented Jul 5, 2021 at 8:43
  • Yes, I've edited the question to include the nginx configuration. Commented Jul 5, 2021 at 8:50
  • "What is the proper way to monitor if my websites are available?" - Please consider elaborating on what you mean by "available". A 404 is different than a 503 which is different from, say, no response at all. Commented Jul 6, 2021 at 9:56
  • To make it clear I want to get the final response code after the redirection, because now instead of 404, 503, 200 ... I always receive 301 Commented Jul 6, 2021 at 10:02

1 Answer 1

1

Just using -L solved my problem So now using

echo $(curl -L mysubhost.com --write-out '%{http_code}' --silent --output /dev/null servername)

will follow the redirection and return the final response code, and based on which you can make your decisions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .