T
T
tgarl2021-06-24 12:05:54
Nginx
tgarl, 2021-06-24 12:05:54

How to write redirects in docker nginx?

Good afternoon.
Tell me how to change the redirect correctly: I need it from without www to www

found this

if ($host ~* www\.(.*)) {
        set $host_without_www $1;
        rewrite ^(.*)$ http://$host_without_www$1 permanent;
    }

reverse
redirects are needed are registered in a separate include file /etc/nginx/vhosts/_redirect;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2021-06-24
@ky0

Why do you need if? Make a separate server block for the non-www host and add an unconditional redirect to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question