Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

/images/stories/2020/confuse-the-hell-out-of-the-spiders_thumb.png

I use CentOS Web Panel (CWP) and want to redirect my secondary parked domain to my main domain both http and https using nginx. Needs some tricks.

So I have my main domain gruz.ml and a secondary one gruz.ml. I want when I visit https://gruz.ml/whatever-path , https://gruz.ml/whatever-path I'm redirected to https://gruz.ml/whatever-path

The most obvoious way is to create a domain in CWP and link it to an existing CWP user public_html folder. And this works, but demands some additional steps. Otherwise there you don't redirect to the main domain, but have your web-site accessible under 2 different domains.

## Add your secondary domain https://ximage.ml/x/2020_04_26_23_40_31_yq_thumb.png

After that the parked domain should work as just another domain without main web-site redirect.

Create CWP nginx templates

To redirect we must create two nginx templates in CWP and apply it to the domain. Two - one for http and one for https.

So if using CLI (as root) go to the folder and create 2 templates like the code below. Don't forget to set MYDOMAIN varaible correctly. In my case I have used MYDOMAIN='gruz.ml';

cd /usr/local/cwpsrv/htdocs/resources/conf/web_servers/vhosts/;
MYDOMAIN='mydomain.com';
cat > redirect-to-$MYDOMAIN.tpl  <<EOL
server {
        listen %ip%:%nginx_port%;
        server_name %domain_idn% %alias_idn%;

        access_log /usr/local/apache/domlogs/%domain%.bytes bytes;
        access_log /usr/local/apache/domlogs/%domain%.log combined;
        error_log /usr/local/apache/domlogs/%domain%.error.log error;

        rewrite ^/(.*) https://${MYDOMAIN}/$1 permanent;
}
EOL;
cat > redirect-to-$MYDOMAIN.stpl  <<EOL
server {
        listen %ip%:%nginx_port% %http2%;
        server_name %domain_idn% %alias_idn%;

        access_log /usr/local/apache/domlogs/%domain%.bytes bytes;
        access_log /usr/local/apache/domlogs/%domain%.log combined;
        error_log /usr/local/apache/domlogs/%domain%.error.log error;

        ssl                  on;
        ssl_certificate      %ssl_cert_path%/%domain%.bundle;
        ssl_certificate_key  %ssl_key_path%/%domain%.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA!RC4:EECDH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS;
        ssl_prefer_server_ciphers   on;

        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 60m;

        rewrite ^/(.*) https://${MYDOMAIN}/$1 permanent;
}
EOL;

Apply your template to the secondary domain

Go to WebServer Settings -> WebServers Domain Conf, select your user and press Add Configuration (Or Edit configuration, if already created).

https://ximage.ml/x/2020_04_27_00_09_25_uv_gf_thumb.png

Next select nginx -> php-fpm, php-fpm and finally redirect-to-mydomain.com (your newly create template). Don't forget to check Rebuild WebServers conf for domain on save. Save

https://ximage.ml/x/2020_04_27_00_14_05_pu_thumb.png

Please register to post comments.

Found a typo? Please select it and press Ctrl + Enter.
FaLang translation system by Faboba
Електронна бібліотека «Exlibris»: історичні дослідження, мемуаристика, публіцистика, художня література Українська етнографія: книги, курси лекцій, статті й матеріали, мапи, фотоальбоми, веб-ресурси Правителі України: портрети, життєписи, матеріали Твори Адріана Кащенка: романтика козацьких часів Народна війна 1917-1932

See a typo?

Select the text block and press

CTRL+Enter

Comments

  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 30.06.2019 11:45
    The fields %TO_NAME% and %TO_USERNAME% are empty

    Read more...

     
  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 30.06.2019 11:43
    My fault, I made it

    Read more...

     
  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 30.06.2019 10:46
    I did. Now I'm asking me how to put the surename into the email... :-|

    Read more...

     
  • NavigationAry - navigate between Joomla menu items like between articles using "prev - next"

    Berndi Berndi 29.06.2019 15:59
    I also miss content in %TO_NAME%

    Read more...

     
  • NotificationAry - get emails on Joomla content is submitted, added or changed

    Berndi Berndi 29.06.2019 15:15
    Hi gruz, I have the problem, that when I use the %AUTHOR% tag, the plugin dosen't send the author ...

    Read more...