Get support for goetas/docker-nginx-redirect

If you're new to LTH, please see our FAQ for more information on what it is we do.

Support Options

Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:

View Open Issues

Take a look to see if anyone else has experienced the same issue as you and if they managed to solve it.

Open an Issue

Make sure to read any relevant guidelines for opening issues on this repo before posting a new issue.

Sponsor directly

Check out the page and see if there are any options to sponsor this project or it's developers directly.

goetas/docker-nginx-redirect

Nginx redirect

This is a very simple nginx docker image that helps you redirecting HTTP requests to the www sub-domain.

Rationale: It is a common use case to have a project on a hypothetical www.example.com. What about requests going to example.com? Of course you can configure your project to redirect requests to the www sub-domain... What is this should happen only for the "production/live" environment and for "staging"? (as most likely is going to look something as www-staging.example.com). On staging having staging.example.com to redirect to www-staging.example.com could make no sense and will require a different rule.

Redirecting to www is not responsibility of "your" application and can be done outside of it. Here it comes useful goetas/nginx-redirect.

Usage

Basic example, using a docker-compose file:

services:
    www_redirector:
      image: goetas/nginx-redirect:latest

An more sophisticated use case is when used in combination with jwilder/nginx-proxy:

services:
    web:
      image: jwilder/nginx-proxy
      ports:
        - "80:80"
  
    myproject:
      image: myproject
      environment:
        VIRTUAL_HOST: www.example.com
         
    www_redirector:
      image: goetas/nginx-redirect:latest
      environment:
        VIRTUAL_HOST: example.com

In this example:

  • web: is listening on the port 80 (is the only container exposed to the outside)
  • myproject: is the image that holds the code for your project, and does not need to be aware which is going to be the hostname where the "project" will be exposed. The proxy will forward to it requests that are directed to www.example.com (thanks to VIRTUAL_HOST=www.example.com)
  • www_redirector: redirects eventual requests from http://example.com to http://www.example.com The proxy will forward to it requests that are directed to example.com (thanks to VIRTUAL_HOST=example.com)

Configuration variables

Using environment variables is possible to customize the redirect-behaviour. All the configurations are optional.

  • REDIRECT_CODE: HTTP redirect code (the default is 301)
  • REDIRECT_SUBDOMAIN: to which sub-domain redirect (the default is to prepend www. to the original hostname)

Other info

The project supports properly HTTPS redirects and respects the X-Forwarded-Proto and X-Forwarded-Port headers.

This image is based on the latest nginx docker image.

Our Mission

We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.

Interesting Articles

Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated

p-e622a1a2