Now here is the situation i have two servers, one is running apache2 and the other is running odoo with nginx, the server that is running odoo doesnot have a public ip, what i am doing is i am using apache as a reverse proxy that forwards request to the second server through local network ip and nginx handles the rest. The configuation of my apache is below.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin sp.example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyRequests off
ProxyPreserveHost On
ProxyPass / http://192.168.0.6/
ProxyPassReverse / http://192.168.0.6/
# WebSocket support for live chat
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule ^/websocket/(.*) ws://192.168.0.6/websocket/$1 [P,L]
ProxyPass /websocket/ ws://192.168.0.6/websocket/
ProxyPassReverse /websocket/ ws://192.168.0.6/websocket/
RequestHeader set Upgrade "websocket" env=websocket_upgrade
RequestHeader set Connection "Upgrade" env=websocket_upgrade
ServerName sp.spaero.sa
SSLCertificateFile /etc/letsencrypt/live/sp.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sp.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
The configuation of nginx on my second server that is running odoo is:
#odoo server
upstream odoo
{
server 127.0.0.1:8069;
}
upstream odoochat
{
server 127.0.0.1:8072;
}
map $http_upgrade $connection_upgrade
{
default upgrade;
'' close;
}
server
{
root /var/www/html;
# Add index.php to the list if you are using PHP
listen 80 default_server;
listen [::]:80 default_server;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# log
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;
# Redirect websocket requests to odoo gevent port
location /websocket
{
proxy_pass http://odoochat;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
#proxy_cookie_flags session_id samesite=lax secure; # requires nginx 1.19.8
}
# Redirect requests to odoo backend server
location /
{
# Add Headers for odoo proxy mode
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_pass http://odoo;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
#proxy_cookie_flags session_id samesite=lax secure; # requires nginx 1.19.8
}
# common gzip
gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
gzip on
}
i have tried ngrok on my odoo server and the livechat is working, that means nginx config is correct, but what adjustments i need to make in apache config to make the livechat works or more correct term is how to make websocket work.