Reverse Proxy Apache with Subdirectory

Adrien548 years ago

Hello,

I use two virtuals machines, one with Traccar and one with a reverse proxy Apache.
I want to access Traccar with https and reverse proxy with this type of url : https://app.****.net/traccar

I configure Apache with this link : https://www.traccar.org/secure-connection/

Here my config


ProxyPass /tracker/api/socket ws://192.168.1.103:8082/api/socket
ProxyPassReverse /tracker/test/api/socket ws://192.168.1.103:8082/api/socket

ProxyPass /tracker http://192.168.1.103:8082/
ProxyPassReverse /tracker http://192.168.1.103:8082/

Module proxy_http and proxy_wstunnel is activated.

When I want access Traccar with my URL : https://app.***.net/tracker I have a blank page with "Powered by Traccar GPS System" and I can't login.

With developper console I have this informations :

Failed to load resource: the server responded with a status of 404 (Not Found) : https://app.***.net/app.css
Failed to load resource: the server responded with a status of 404 (Not Found) : https://app.***.net/load.js
Failed to load resource: the server responded with a status of 404 (Not Found) : https://app.***.net/app.css

The URL write by browser is not correct but I don't known how I can change it...

If I don't add a subdirectory and access directly to https://app.***.net/ ; Traccar work correctly...

Can you help me ?

Thank you in advance

Anton Tananaev8 years ago

I'm not sure why it doesn't work. Traccar uses relative paths everywhere, so I don't understand why it tries to load files from root path.

Adrien548 years ago

Hello,

I have test in local with this config :

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/

Same problems, files don't load...

Any ideas ?

Thanks

Anton Tananaev8 years ago

Do you have a URL I can try myself?

Adrien548 years ago

Hello,

You can try with this URL :
https://example.com/traccar

Corresponding at this configuration :

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

ProxyPass /traccar http://192.168.1.103:8082/
ProxyPassReverse /traccar http://192.168.1.103:8082/
Anton Tananaev8 years ago

I think I know what's your problem. In your config you are missing forward slashes. I should be something like this:

ProxyPass /traccar/ http://192.168.1.103:8082/
ProxyPassReverse /traccar/ http://192.168.1.103:8082/
Adrien548 years ago

Hello,

Can you hide the URL in the previous post ?

Yes it's work, I can connect to Traccar.
But now, after connection I have this error : Web socket connection error

And many errors about API in the developper console :
Errors developper console

I have change the config like this :

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

ProxyPass /traccar/ http://192.168.1.103:8082/
ProxyPassReverse /traccar/ http://192.168.1.103:8082/

But no work...

I have also test with one virtual machine with Traccar + Apache2 : it's the same, no work and same errors...

Thank you

Adrien

Anton Tananaev8 years ago

Why did you add forward slashes to the socket? It's not needed there.

Adrien548 years ago

I have tested with forward slashes and no forward slashes. Same errors for both

Can you hide URL in post #15445, please ?

Anton Tananaev8 years ago

Does it work if you proxy without adding "traccar" to the path?

Adrien548 years ago

Yes without subdirectory /traccar it work correctly

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

ProxyPass / http://192.168.1.103:8082/
ProxyPassReverse / http://192.168.1.103:8082/
Anton Tananaev8 years ago

Why do you have 3 slashes after "ws"? Are you sure it works like this?

You can try to search on forum. I believe some people managed to configure subdirectory proxying with Traccar successfully.

Adrien548 years ago

Sorry it is a mistyping in forum, my conf is with 2 slashes.
I have search on the forum, I have not found a config with a subdirectory, have you an example ?

Anton Tananaev8 years ago
Adrien548 years ago

Hello,

I have test your solution in Github but it doesn't work.

Finally, with this configuration : (without subdirectoy)

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

ProxyPass / http://192.168.1.103:8082/
ProxyPassReverse / http://192.168.1.103:8082/

It work but in right of page I have this error message : Web socket connection error
In developper console, I have this message : WebSocket connection to 'wss://app.****.net/api/socket' failed: Error during WebSocket handshake: Unexpected response code: 405

Have you ideas ?

Thank you,

Adrien