N
N
nemurenai_yuki2022-03-16 07:10:23
Nginx
nemurenai_yuki, 2022-03-16 07:10:23

Redirect Bitrix VM + Nginx. What is the problem?

Hello! There was a problem with setting up a redirect after migrating the Bitrix portal to a new domain: the redirect works from http to https of the new domain, but does not work from https://olddomain.ru to https://newdoman.com . If you add rewrite to both sections (http, https), then browsers give an error about a cyclic redirect. Please tell me the solution :)
The nginx configuration is as follows:

ssl.s1.conf


# Default SSL certificate enabled website
server {

listen 80;
server_name bitrix.olddomain.ru;
rewrite ^ https://bitrix.newdomain.com$request_uri;
}

server {
listen 443 ssl http2;
server_name bitrix.newdomain.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 $host:443;
proxy_set_header HTTPS YES;

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

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

# custom options for sites; doesn't changes on update
include bx/site_settings/default/*.conf;
# Include parameters common to all websites
include bx/conf/bitrix.conf;

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


s1.conf

# Default website
server {

listen 80;
server_name bitrix.olddomain.ru;

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;

set $proxyserver "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; }

# custom options for sites; doesn't changes on update
include bx/site_settings/default/*.conf;
# Include parameters common to all websites
include bx/conf/bitrix.conf;

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


UPD: .htaccess config
.htaccess

Options -Indexes
ErrorDocument 404 /404.php


php_flag session.use_trans_sid off
#php_flag default_charset UTF-8
#php_value display_errors 1



php_flag session.use_trans_sid off
#php_flag default_charset UTF-8
#php_value display_errors 1



Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$
RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]



DirectoryIndex index.php index.html



ExpiresActive on
ExpiresByType image/jpeg "access plus 3 day"
ExpiresByType image/gif "access plus 3 day"
ExpiresByType image/png "access plus 3 day"
ExpiresByType text/css "access plus 3 day"
ExpiresByType application/javascript "access plus 3 day"


Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Dmitriev, 2022-03-16
@SignFinder

1. In nginx, the correct approach is through return
https://serversforhackers.com/c/redirect-http-to-h...
2. In BitrixVM, the nginx + apache bundle, so the redirect is still in .htaccess

V
Vyacheslav Zhgilev, 2022-03-16
@jazzz

Isn't it easier to set up a redirect from the old to the new one on the domain registrar?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question