Enable Dark Mode!
how-to-configure-nginx-for-your-ngrok.jpg
By: Abhin K

How to Configure Nginx for Your Ngrok (Odoo 17)

Technical Odoo 17

In this extended guide, we'll not only configure Nginx for Odoo with least connection load balancing but also cover the process of obtaining and using self-signed SSL certificates to enhance the security of your local development environment.

Prerequisites:

Before proceeding, ensure the following prerequisites are met:
1. Ubuntu installed on your local machine.
2. Nginx installed. If not, you can install it using the following command:
sudo apt-get update
sudo apt-get install nginx
3. Odoo installed and running on the specified ports (8039 and 8047 in this example).

Step 1: Obtain Self-Signed SSL Certificates

Run the following commands to generate a self-signed SSL certificate:
sudo mkdir /etc/nginx/ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/key.pem -out /etc/nginx/ssl/certificate.pem
Follow the on-screen prompts to provide information for your certificate.

Step 2: Edit Nginx Configuration File

Open the Nginx configuration file using your preferred text editor:
sudo nano /etc/nginx/sites-available/default

Step 3: Configure Nginx for Odoo with Least Connection Load Balancing and SSL

Replace the existing configuration with the provided Odoo-specific configuration, including SSL settings:
upstream odoo {
    least_conn;  # Enable least connections load balancing
    server 127.0.0.1:8039;
    server 127.0.0.1:8047;
    # Add more Odoo servers if needed
    # server additional_ip_or_hostname:port;
}
server {
    listen 443 ssl;
    server_name odoo_dev_test.com;
    ssl on;
    ssl_certificate /etc/nginx/ssl/certificate.pem;
    ssl_certificate_key /etc/nginx/ssl/key.pem;
    ssl_session_timeout 30m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RS$';
    ssl_prefer_server_ciphers on;
    gzip on;
    gzip_min_length 1000;
    location / {
        proxy_pass http://odoo;
        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;
    }
    # WebSocket Configuration for Odoo (longpolling and websocket)
    location /longpolling {
        proxy_pass http://odoo;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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;
    }
    location /websocket {
        proxy_pass http://odoo;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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;
    }
}
The upstream block defines a group of backend servers. In this case, it's named odoo.
least_conn enables the least connection load balancing algorithm, distributing incoming connections to the server with the fewest active connections.
Two Odoo servers are specified on ports 8039 and 8047. You can add more servers if needed by uncommenting and modifying the line with additional server information.
The server block defines the configuration for the Nginx server.
listen 443 ssl; specifies that the server will listen on port 443 for HTTPS connections.
server_name odoo_dev_test.com; sets the domain name for the server. Replace it with your specific domain or localhost address.
SSL configuration includes specifying the SSL certificate and key paths, setting the session timeout, defining supported protocols and ciphers, and enabling gzip compression.
The location / block handles general proxying for requests.
proxy_pass http://odoo; forwards requests to the defined upstream servers (Odoo backend).
proxy_set_header directives forward various headers to the upstream server for better request handling.
Additional location blocks are included to handle WebSocket configurations for longpolling and regular WebSocket connections. These are essential for Odoo's real-time features.
Ensure to replace `odoo_dev_test.com` with your specific domain or localhost address.
Replace 8039 and 8047 with the actual ports where your Odoo servers are running. If you have additional Odoo servers, uncomment and modify the line with additional server information.
If you have more Odoo servers with different IP addresses or hostnames, uncomment and modify the line with additional server information accordingly.

Step 4: Test Nginx Configuration

Before applying the changes, test the Nginx configuration to ensure there are no syntax errors:
sudo nginx -t
If the test is successful, proceed to the next step.

Step 5: Reload Nginx

Apply the changes by reloading Nginx:
sudo systemctl reload nginx
Now after setting up the nginx, expose your local server using ngrok,
ngrok http 443
When you navigate to the network table in the inspect tool after clicking on the URL provided by ngrok, you can see that the server is configured using nginx.

Conclusion:

You have successfully configured Nginx for Odoo with the least connection load balancing on multiple ports, and you've added an extra layer of security using self-signed SSL certificates. This setup ensures a secure and efficient local development environment for your Odoo projects. Customize the configuration further based on your specific requirements, and enjoy coding with enhanced security and performance.
To read more about using NGROK with Odoo, refer to our blog How to Use NGROK With Odoo


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message