Outside site in Bitrix24 box

This article will discuss how to add a third-party site in Bitrix24 box and what steps are required to configure nginx and apache.

New site in Bitrix24 box

Suppose we have a ready-made website that we would like to place on the Bitrix24 box and we want it to work in the same way as bitrix itself in the nginx + apache bundle. First, let’s create a directory for our site (all actions are performed with root privileges):

# mkdir /home/bitrix/pocketadmin.tech

As you can see from the example, the site will be located in the home directory of the bitrix user next to the main one – www.

In our case, the site will consist of one page – index.php, located in /home/bitrix/pocketadmin.tech/index.php:

<?php
echo "This is PocketAdmin.tech";
?>

Let’s make the owner of the new directory and all files in it the bitrix user:

# chown bitrix: -R /home/bitrix/pocketadmin.tech/

This completes the work with the site, move on to the front-end and back-end servers settings.

Configure apache

Let’s create a file with settings for our site in the directory with apache configuration files:

# nano /etc/httpd/bx/conf/pocketadmin.tech.conf

And we will add the following to it:

Listen 127.0.0.1:18888
<VirtualHost 127.0.0.1:18888>
        ServerAdmin admin@pocketadmin.tech
        ServerName pocketadmin.tech
        DocumentRoot /home/bitrix/pocketadmin.tech

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>

        <DirectoryMatch .*\.svn/.*>
                 Require all denied
        </DirectoryMatch>

        <DirectoryMatch .*\.git/.*>
                 Require all denied
        </DirectoryMatch>

        <DirectoryMatch .*\.hg/.*>
                 Require all denied
        </DirectoryMatch>

        <Directory /home/bitrix/pocketadmin.tech/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                DirectoryIndex index.php index.html index.htm
                php_admin_value session.save_path /tmp/php_sessions/www
                php_admin_value upload_tmp_dir /tmp/php_upload/www
        Require all granted
        </Directory>

        ErrorLog logs/error_log
        # Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
        LogLevel warn

        CustomLog logs/access_log combined

        <IfModule mod_rewrite.c>
                #Nginx should have "proxy_set_header HTTPS YES;" in location
                RewriteEngine On
                RewriteCond %{HTTP:HTTPS} =YES
                RewriteRule .* - [E=HTTPS:on,L]
        </IfModule>
</VirtualHost>


What you should pay attention to:

  • in the first two lines, Listen 127.0.0.1:18888 and <VirtualHost 127.0.0.1:18888> 18888 is an arbitrary free port that must be different from the standard 8888.
  • ServerName contains the domain name of your site, in the example it is pocketadmin.tech
  • in the DocumentRoot and in <Directory, the location of the site is indicated, the directory that we created in the first step. In this case, it is /home/bitrix/pocketadmin.tech.

Configure nginx

Let’s create a file with settings for our site in the directory with available nginx configuration files:

# nano /etc/nginx/bx/site_avaliable/pocketadmin.tech.conf

with the following content:

server {
                listen 80;
                server_name pocketadmin.tech;
                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;

                set $proxyserver        "http://127.0.0.1:18888";
                set $docroot            "/home/bitrix/pocketadmin.tech";

                index index.php;
                root /home/bitrix/pocketadmin.tech;

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

                # Main location
                location / {

                    proxy_pass $proxyserver;
                }

                # php file processing
                location ~ \.php$ {
                    proxy_pass $proxyserver;
                }

}


This configuration file differs little from the standard one, but you should pay attention to:

  • server_name – site domain, pocketadmin.tech;
  • in set $proxyserver “http://127.0.0.1:18888”; you must specify the port that we assigned in the apache settings.
  • in set $docroot “/home/bitrix/pocketadmin.tech”; and root /home/bitrix/pocketadmin.tech; the directory with our site is located

The last step will be to create a symbolic link in the directory of allowed sites to our site in bitrix24 box:

# ln -s /etc/nginx/bx/site_avaliable/pocketadmin.tech.conf /etc/nginx/bx/site_enabled/pocketadmin.tech.conf

It remains only to reload the configuration files:

# service httpd reload
# servcie nginx reload

Leave a Comment