J
J
Jacob2011-12-22 17:28:31
Nginx
Jacob, 2011-12-22 17:28:31

Nginx and forced redirect to https?

Actually, it became necessary to redirect users of one resource forcibly to https due to some delicacy of the information that is available on the resource.

Is there such a hat in the wirthost config:

location /somewhere {
rewrite ^/(.*) https://$server_name$request_uri ? permanent;
}

Considering that a separate virthost was configured for access via https a long time ago (in a separate file), I just threw these two and a half lines into the virthost running on port 80, and everything turned out fine, it would seem.

The downside is that users love bookmarks. If you tell the browser resource.ru/somewhere , then a redirect to a secure connection will work. If we sayresource.ru/somewhere/index.php , or show your hands to the desired script, the redirect does not work.

How could the desired be realized?

Wednesday - Squeeze, nginx 1.0.10 and php5-fpm 5.3.8-1 from dotdeb. The rest, I think, is irrelevant.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dzuba, 2011-12-22
@ksenobayt

Try outside of location like this:

server {
  server_name ...;
  rewrite ^(/somewhere/.*)$ https://$host$1 permanent;
  ...
}

N
NeX, 2011-12-22
@NeX

location ~* ^/somewhere(.*) {
rewrite ^/(.*) https://$server_name$request_uri? permanent;
}

V
Vlad Zhivotnev, 2011-12-22
@inkvizitor68sl

rewrite ^/somewhere(.*) https://$server_name/somewhere$1 permanent;
If you need a specific section.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question