jackieli123723 / jackieli123723.github.io

✅lilidong 个人博客
9 stars 0 forks source link

使用Nginx配置Odoo作为反向代理 #70

Open jackieli123723 opened 5 years ago

jackieli123723 commented 5 years ago

使用Nginx配置Odoo作为反向代理

default Odoo是世界上最受欢迎的商业软件之一,它包含多个有用的模块,如客户关系管理(CRM),销售点,项目管理,库存管理,自动发票,会计,电子商务,库存管理和多得多。

Odoo带有一个内置的Web服务器,但在大多数情况下,建议在它前面有一个反向代理,它将充当客户端和Odoo服务器之间的中介。

本文提供有关如何将Nginx用作SSL终止和反向代理到Odoo的说明

将Nginx配置为反向代理 使用反向代理可以带来很多好处,例如负载平衡,SSL终止,缓存,压缩,服务静态内容等等。

在此示例中,我们将配置SSL终止,HTTP到HTTPS重定向,缓存静态文件并启用GZip压缩。

sudo nano /etc/nginx/sites-enabled/odoo.example.com

/etc/nginx/sites-enabled/odoo.example.com
upstream odoo {
 server 127.0.0.1:8069;
}

upstream odoo-chat {
 server 127.0.0.1:8072;
}

server {
    server_name odoo.example.com;
    return 301 https://odoo.example.com$request_uri;
}

server {
   listen 443 ssl http2;
   server_name odoo.example.com;

   ssl_certificate /path/to/signed_cert_plus_intermediates;
   ssl_certificate_key /path/to/private_key;
   ssl_session_timeout 1d;
   ssl_session_cache shared:SSL:50m;
   ssl_session_tickets off;

   ssl_dhparam /path/to/dhparam.pem;

   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
   ssl_prefer_server_ciphers on;

   add_header Strict-Transport-Security max-age=15768000;

   ssl_stapling on;
   ssl_stapling_verify on;
   ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;
   resolver 8.8.8.8 8.8.4.4;

   access_log /var/log/nginx/odoo.access.log;
   error_log /var/log/nginx/odoo.error.log;

   proxy_read_timeout 720s;
   proxy_connect_timeout 720s;
   proxy_send_timeout 720s;
   proxy_set_header X-Forwarded-Host $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;

   location / {
     proxy_redirect off;
     proxy_pass http://odoo;
   }

   location /longpolling {
       proxy_pass http://odoo-chat;
   }

   location ~* /web/static/ {
       proxy_cache_valid 200 90m;
       proxy_buffering    on;
       expires 864000;
       proxy_pass http://odoo;
  }

  # gzip
  gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
  gzip on;
}

不要忘记将odoo.example.com替换为您的Odoo域,并为SSL证书文件设置正确的路径。

完成后保存文件并重新启动Nginx服务:

systemctl restart nginx

更改绑定界面 此步骤是可选的,但这是一种很好的安全措施。

默认情况下,Odoo服务器侦听8069所有接口上的端口。如果要禁用对Odoo实例的直接访问,请打开Odoo配置文件,并在文件末尾添加以下两行:

/etc/odoo.conf
xmlrpc_interface = 127.0.0.1
netrpc_interface = 127.0.0.1

保存配置文件并重新启动Odoo服务器以使更改生效:

systemctl restart odoo