Secure connection Centos 8

Angel4 years ago

So I have a domain domain.com with this conf file

<`VirtualHost *:80>
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/domain.com/html
    Redirect permanent / https://domain.com/

<`/VirtualHost>

<`VirtualHost *:443>
  ServerName domain.com
  ServerAlias www.domain.com

  Protocols h2 http:/1.1

  <If "%{HTTP_HOST} == 'www.domain.com'">
    Redirect permanent / https://domain.com/
  </If>

  DocumentRoot /var/www/domain.com/html
  ErrorLog /var/www/domain.com/log/error.log
  CustomLog /var/www/domain.com/log/requests.log combined

  SSLEngine On
  SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem


<`/VirtualHost>

And it works fine. I want now to add traccar with proxy so I will have https to this domain as domain.com/traccar
I read the https://www.traccar.org/secure-connection/ but I don't know how to use it.

I added those 3 lines in the 443 virtualhost and after changed the
setsebool -P httpd_can_network_connect 1

ProxyPreserveHost On
ProxyPass "/traccar" "http://127.0.0.1:8082"
ProxyPassReverse "/traccar" "http://127.0.0.1:8082""

and after restarting httpd I can login to mydomain.com/traccar
BUT
Having both sites open (mydomain.com/traccar and mydomain.com:8082) the new one is not responding as fast as the second.
For example I enable the android client and I can see it immediately on the 8082 but after a while in the /traccar.
Basic problem is that in /traccar I get web socket connection error and I do not see my spot on map.

Removing the previous lines and adding the one on the https://www.traccar.org/secure-connection/

ProxyRequests off

ProxyPass /traccar/api/socket ws://localhost:8082/api/socket
ProxyPassReverse /traccar/api/socket ws://localhost:8082/api/socket

ProxyPass /traccar/ http://localhost:8082/
ProxyPassReverse /traccar/ http://localhost:8082/
ProxyPassReverseCookiePath / /traccar/

Redirect permanent /traccar /traccar/

I see the same problems plus I cannot use mydomain.com/traccar as server name in the android app. It does not connect.

I am a bit confused as I am amateur sysadmin!

Any help will be appreciated!

Thank you!

Anders Yuran4 years ago

I have only added these lines in the hostfile and nothing else.

ProxyPass /api/socket ws://localhost:8082/api/socket
ProxyPassReverse /api/socket ws://localhost:8082/api/socket
ProxyPass / http://localhost:8082/
ProxyPassReverse / http://localhost:8082/

Works flawless
But I see that you use a subfolder and that is different. I have the traccar as a sub domain

Angel4 years ago

Ok so I create new subdomain traccar.mydomain.com create new certificate (that was so easy with certbot-auto --apache)
and end with 2 files
First is the traccar.mydomail.com.conf

<VirtualHost *:80>

 ServerName traccar.domain.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =traccar.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

And the other traccar.mydomail.com-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>

 ServerName traccar.domain.com
 

 ProxyPass /api/socket ws://localhost:8082/api/socket
 ProxyPassReverse /api/socket ws://localhost:8082/api/socket

 ProxyPass / http://localhost:8082/
 ProxyPassReverse / http://localhost:8082/


SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/traccar.domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/traccar.domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

It works but I cannot see my live dot.
With staticip:8082 I see dot
but with traccar.mydomain.com i get this dot and when I get offline I can not see my last position.

Anders Yuran4 years ago

The setup is correct now. Your problem must have another reason

JCV3 years ago

Greetings all,

I used your configuration to create the virtual server on Centos 8, read everything I found on the Internet but I cannot put ssl to work. Is there any guide for Traccar os Centos 8. Can you help me?