Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two applications on the same server #288

Closed
DSMejantel opened this issue Apr 12, 2024 · 1 comment
Closed

Two applications on the same server #288

DSMejantel opened this issue Apr 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@DSMejantel
Copy link

Introduction

When we want to launch 2 differents appli with SQLpage with 2 differents ports for example 8080 and 8081 and behind 2 https domain
it's impossible to reach the server

Apr 11 20:28:30 ns376272 sqlpage.bin[1546]: [2024-04-11T18:28:30.819Z INFO  sqlpage] Server started successfully.
Apr 11 20:28:30 ns376272 sqlpage.bin[1546]:         SQLPage is now running on https://rucher.dsoulie.fr/
Apr 11 20:28:30 ns376272 sqlpage.bin[1546]:         You can write your website's code in .sql files in /var/www1/RUCHER.
Apr 11 20:28:30 ns376272 sqlpage.bin[1546]: [2024-04-11T18:28:30.819Z ERROR sqlpage] Another program is already using port 8081 (maybe another i>
Apr 11 20:28:30 ns376272 sqlpage.bin[1546]:
Apr 11 20:28:30 ns376272 sqlpage.bin[1546]:     Caused by:
Apr 11 20:28:30 ns376272 sqlpage.bin[1546]:         Address already in use (os error 98)
@DSMejantel DSMejantel added the bug Something isn't working label Apr 12, 2024
@lovasoa
Copy link
Collaborator

lovasoa commented Apr 12, 2024

Running two applications on the same server

Without HTTPS, on different ports

You can run the two applications by specifying different values for the port configuration variable for the two applications, and omitting https_domain.

On the same port

If you want to run both applications on the same port (HTTPS on port 443, or HTTP on port 80) for instance,
you will need to put a reverse proxy such as nginx between the public web and your application.

The reverse proxy will receive requests, and based on their contents, decide which SQLPage instance to forward them to.

Example nginx configuration

  • Install nginx using the command: sudo apt-get install nginx on Ubuntu.
  • Configure Nginx to listen on port 80 and manage HTTP requests. Here are sample configuration files for HTTP in /etc/nginx/sites-available/:

HTTP configuration for site1 (site1-http.conf):

server {
    listen 80;
    server_name site1.com;

    location / {
        proxy_pass http://localhost:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

HTTP configuration for site2 (site2-http.conf):

server {
    listen 80;
    server_name site2.com;

    location / {
        proxy_pass http://localhost:8082;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
  • replace
    • site1 and site2 with your actual domain names,
    • 8081 and 8082 with the ports you configured SQLPage to listen to
  • Install certbot
  • Use Certbot to obtain and configure Let's Encrypt certificates. Example command:
    sudo certbot --nginx -d site1.com -d site2.com
    
  • Activate both configurations with the command:
    sudo ln -s /etc/nginx/sites-available/site1-http.conf /etc/nginx/sites-enabled/
    sudo ln -s /etc/nginx/sites-available/site2-http.conf /etc/nginx/sites-enabled/
    
  • Restart Nginx to apply the changes:
    sudo systemctl restart nginx
    

Note the logs in the post above demonstrate a bug in sqlpage when trying to listen on both https and http (when the configuration file contains both a non-443 port and an https_domain entry). This is not related to multisite installations, but I will try to fix it soon. The bug is in https://github.com/lovasoa/SQLpage/blob/main/src/webserver/http.rs#L523-L529 SQLPage tries to bind to the http port twice instead of binding once to the http port and once to the https port.

@lovasoa lovasoa changed the title Two applis on the same server Two applications on the same server Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants