A
A
Akram2016-02-22 12:15:39
Nginx
Akram, 2016-02-22 12:15:39

How to make the correct redirect https Nginx/BitrixVM?

The following settings are used:

s1.conf
  # Default website
  server {

    listen 80;
    server_name test.com www.test.com;
    return 301 https://test.com$request_uri;  # enforce https
    
    server_name_in_redirect off;
    
    access_log /var/log/nginx/access.log main;
    error_log  /var/log/nginx/error.log warn;
    
    proxy_set_header	X-Real-IP        $remote_addr;
    proxy_set_header	X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header	Host $host:80;
    proxy_set_header<	X-Forwarded-Host $http_host

    set $proxyserver	"http://127.0.0.1:8888";
    set $docroot		"/home/bitrix/www";

    index index.php;
    root /home/bitrix/www;

    # Redirect to ssl if need
    if (-f /home/bitrix/www/.htsecure) { rewrite ^(.*)$ https://$host$1 permanent; }

    # Include parameters common to all websites
    include bx/conf/bitrix.conf;

    # Include server monitoring locations
    include bx/server_monitor.conf;
  }

s1_ssl.conf

  # Default SSL certificate enabled website
  server {
    listen	443 default_server ssl;
    server_name test.com;
    
    
    # Enable SSL connection
    include	bx/conf/ssl.conf;
    server_name_in_redirect	off;

    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:443;
    proxy_set_header	X-Forwarded-Host $http_host;
    proxy_set_header    X-Forwarded-Proto https;
    proxy_set_header	HTTPS 		YES;

    set $proxyserver	"http://127.0.0.1:8888";
    set $docroot		"/home/bitrix/www";

    index index.php;
    root /home/bitrix/www;

    # Include parameters common to all websites
    include bx/conf/bitrix.conf;

    # Include server monitoring API's
    include bx/server_monitor.conf;

  }

If you use a URL like https://test.com/xyz/ ( http://test.com/xyz/or equivalent with www) , then everything works fine, but if like this: https://test.com/xyz , then the result is: 400 Bad Request, The plain HTTP request was sent to HTTPS port:
curl -I -k https://test.com/xyz
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Mon, 22 Feb 2016 09:13:28 GMT
Content-Type: text/html; charset=iso-8859-1
Connection: keep-alive
Location: http://test.com:443/xyz/
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN

What can be wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Biryukov, 2016-03-11
@Akram

honestly, forgive my colleagues in the "pen", I don't really want to be puzzled by the repost, what I knew I wrote on this topic here: dev.1c-bitrix.ru/community/forums/messages/forum32...
may the force be with you!

D
Dmitry Voronkov, 2016-02-22
@DmitryVoronkov

The problem is not in NGINX, I'm not sure, but I think that Bitrix has settings for urls. Look at this line.

M
metajiji, 2016-02-22
@metajiji

As for the slash, it’s still simple:
But it’s better if the application itself understands that the slash should be added if it suddenly doesn’t exist, because in the current configuration all locations are given to the conscience of the application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question