Deploying a Rust-Actix project on same domain and VPS as a Laravel project?

Hello

I have written a platform for 85% in Rust. All the business logic is written in Rust-Actix and the Rust-code also contains some Routes to handle GET/POST-requests and to serve some pages as well. Now I am finishing up the pretty basic website to promote my platform, that basic site is written in Laravel and also contains routes to serve webpages. Can this Laravel- and Rust-project co-exist on the same VPS linked to the same domain-name?

For example:

example.com/admin/ -> Rust route
example.com/save-some-object/ (POST) -> Rust route
example.com/article/{id} -> Rust route
example.com -> Laravel route
example.com/about -> Laravel route

is this possible? I think there might be a problem with 1) Running the two separate projects both on port 80/443 (this is necessary I think?). And if I give in a route which does not exist in Laravel, but does exist in Rust-Actix, the Laravel might return a 404?

I am only thinking of this just now...

Thanks.

Hi ONiel,

Yes, it is possible serve multiple back-ends (PHP + Rust) on the same VPS and IP address. One limitation is that it is (to my knowledge) not possible to run multiple applications on the same port, for example 80 or 443. However, you can configure one application to run on this port, which can then forward requests internally to another application that is listening on a different port (like 8080).

A configuration that should work for your situation is this:

  • NGINX webserver on port 80 and 443
  • PHP-fpm on port 9000
  • Rust on port 8080

Then you will have to configure NGINX to suit your needs. You can specify some rules on whether a request should be forwarded to your PHP application or your Rust port (using a reverse proxy). The easiest way to do this is to configure a prefix, for example all requests starting with /admin/ go to rust, while other requests go to PHP.

It should also be possible to configure a 404 logic like you suggested, where it checks Laravel first and then if a 404 is returned tries Rust. However, it will increase the latency of your rust requests slightly and might be a little bit difficult to setup.

Reading How To Install and Configure Laravel with Nginx on Ubuntu 20.04 (LEMP) | DigitalOcean should give you an idea of how to configure Laravel on with NGINX. From there the next step would be to read up on NGINX reverse proxies.

On a side-note, you might want to setup a port firewall on your VPS so that people can only access your application via ports 80 and 443, and directly through port 8080.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.