登入阿里云SSL证书管理,点击购买免费版证书配置好域名后下载nginx证书
有了证书之后,第一步上传证书到服务器,配置nginx,我这配置了两个域名对应odoo两个新建的网站域名
vi /etc/nginx/conf.d/域名.conf
#odoo server
upstream odoo {
server 127.0.0.1:8069;
}
upstream odoochat {
server 127.0.0.1:8072;
}
# http -> https
server {
listen 80;
server_name www.xxx.com.cn xxx.com.cn;
#将所有HTTP请求通过rewrite指令重定向到HTTPS。
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name www.xxx.com.cn xxx.com.cn;
#配置www域名让xxx.com.cn域名也重定向跳转到www.xxx.com.cn
if ($host != 'www.xxx.com.cn') {
rewrite ^/(.*)$ https://www.xxx.com.cn/$1 permanent;
}
root html;
index index.html index.htm;
ssl_certificate cert/5032395_www.xxx.com.cn.pem; #需要将cert-file-name.pem替换成已上传的证书文件的名称。
ssl_certificate_key cert/5032395_www.xxx.com.cn.key; #需要将cert-file-name.key替换成已上传的证书密钥文件的名称。
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# Add Headers for odoo proxy mode
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;
# log
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;
# Redirect longpoll requests to odoo longpolling port
location /longpolling {
proxy_pass http://odoochat;
}
# Redirect requests to odoo backend server
location / {
proxy_redirect off;
client_max_body_size 64m; #表示最大上传10M,需要多大设置多大。
proxy_pass http://odoo;
}
# common gzip
gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
gzip on;
}
# http -> https
server {
listen 80;
server_name tb.xxx.com.cn;
#将所有HTTP请求通过rewrite指令重定向到HTTPS。
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name tb.xxx.com.cn;
root html;
index index.html index.htm;
ssl_certificate cert/5033308_tb.xxx.com.cn.pem; #需要将cert-file-name.pem替换成已上传的证书文件的名称。
ssl_certificate_key cert/5033308_tb.xxx.com.cn.key; #需要将cert-file-name.key替换成已上传的证书密钥文件的名称。
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# Add Headers for odoo proxy mode
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;
# log
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;
# Redirect longpoll requests to odoo longpolling port
location /longpolling {
proxy_pass http://odoochat;
}
# Redirect requests to odoo backend server
location / {
proxy_redirect off;
client_max_body_size 64m; #表示最大上传10M,需要多大设置多大。
proxy_pass http://odoo;
}
# common gzip
gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
gzip on;
}