我想在同一台服务器上运行多个子域,每个子域连接到不同的odoo实例,并且所有实例都在不同的端口上运行。但是,我无法让其中一个子域工作,这是我的配置文件,我知道其中只有一个是子域,另一个是正确的域,但是您可以明白这一点:
example1.com.conf
# Odoo servers
upstream odoo {
server 127.0.0.1:8030;
}
upstream odoochat {
server 127.0.0.1:8072;
}
# HTTP -> HTTPS
server {
listen 80;
server_name www.example1.com example1.com;
include snippets/letsencrypt.conf;
return 301 https://example1.com$request_uri;
}
# WWW -> NON WWW
server {
listen 443 ssl http2;
server_name www.example1.com;
ssl_certificate /etc/letsencrypt/live/example1.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example1.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example1.com/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;
return 301 https://example1.com$request_uri;
}
server {
listen 443 ssl http2;
server_name example1.com;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# Proxy headers
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;
# SSL parameters
ssl_certificate /etc/letsencrypt/live/example1.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example1.com/privkey.pem
include snippets/ssl.conf;
include snippets/letsencrypt.conf;
# log files
access_log /var/log/nginx/odoo.access.log;
error_log /var/log/nginx/odoo.error.log;
# Handle longpoll requests
location /longpolling {
proxy_pass http://odoochat;
}
# Handle / requests
location / {
proxy_redirect off;
proxy_pass http://odoo;
}
# Cache static files
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;
}
example2.mydomain.com
# Odoo servers
upstream example2 {
server 127.0.0.1:8015;
}
upstream example2-chat {
server 127.0.0.1:8072;
}
# HTTP -> HTTPS
server {
listen 80;
server_name www.example2.mydomain.com example2.mydomain.com;
include snippets/letsencrypt.conf;
return 301 https://example2.mydomain.com$request_uri;
}
# WWW -> NON WWW
server {
listen 443 ssl http2;
server_name www.example2.mydomain.com;
ssl_certificate /etc/letsencrypt/live/example2.mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example2.mydomain.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example2.mydomain.com/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;
return 301 https://example2.mydomain.com$request_uri;
}
server {
listen 443 ssl http2;
server_name example2.mydomain.com;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
# Proxy headers
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;
# SSL parameters
ssl_certificate /etc/letsencrypt/live/example2.mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example2.mydomain.com/privkey.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;
# log files
access_log /var/log/nginx/example2.access.log;
error_log /var/log/nginx/example2.error.log;
# Handle longpoll requests
location /longpolling {
proxy_pass http://example2-chat;
}
# Handle / requests
location / {
proxy_redirect off;
proxy_pass http://example2;
}
# Cache static files
location ~* /web/static/ {
proxy_cache_valid 200 90m;
proxy_buffering on;
expires 864000;
proxy_pass http://example2;
}
# Gzip
gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
gzip on;
}
example1.com
工作得很好,但是,每当我点击 example2.mydomain.com
上的任何内容时,它都会将我重定向到上游的名称,例如:
example2.mydomain.com/web
example2/web
example2.mydomain.com/web
就可以了我已经阅读了文档、文章等,但无法弄清楚配置中缺少什么?这是 odoo 的事情,因为默认的
odoo & odoochat
上游正在工作,但不是我定义的自定义上游。
这是我为客户的生产和登台环境使用的两个配置。
效果很好。
但是,不要忘记更改一些内容,例如同时运行 Odoo、使用各自的长轮询和 http 端口更改 odoo.conf(和 odoo2.conf)文件、在 Odoo 的系统参数中设置 web.base.url 等.
在上面的示例中,我看到两种配置都使用相同的长轮询端口,不确定这是否是一个好主意:)
如果您需要更多详细信息,请随时询问我。
(这一切都在 Ubuntu 20.04 上)
生产:
#odoo server
upstream odoo {
server 127.0.0.1:8069;
}
upstream odoochat{
server 127.0.0.1:8092;
}
server {
server_name example.com;
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;
proxy_pass http://odoo;
}
# common gzip
gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
gzip on;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
}
server_name example.com;
listen 80;
return 404;
}
分期:
#odoo server
upstream odoostaging {
server 127.0.0.1:8079;
}
upstream odoochatstaging {
server 127.0.0.1:8082;
}
server {
server_name staging.example.com;
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://odoochatstaging;
}
# Redirect requests to odoo backend server
location / {
proxy_redirect off;
proxy_pass http://odoostaging;
}
# common gzip
gzip_types text/css text/scss text/plain text/xml application/xml application/json application/javascript;
gzip on;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/staging.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/staging.example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = staging.example.com) {
return 301 https://$host$request_uri;
}
server_name staging.example.com;
listen 80;
return 404;
}
如果您需要它们,这里是 Odoo 配置:
/etc/odoo/odoo.conf
[options]
addons_path = /home/ubuntu/prod/odoo/addons,/home/ubuntu/prod/enterprise,/home/ubuntu/prod/custom
admin_passwd = mySuperAdminPassword
csv_internal_sep = ,
data_dir = /var/lib/odoo/.local/share/Odoo
db_host = localhost
db_maxconn = 64
db_name = prodDb
db_password = prodDbPassword
db_port = False
db_sslmode = prefer
db_template = template0
db_user = myDbUser
dbfilter = ^prodDb$
demo = {}
email_from = False
geoip_database = /usr/share/GeoIP/GeoLite2-City.mmdb
http_enable = True
http_interface =
http_port = 8069
import_partial =
limit_memory_hard = 2684354560
limit_memory_soft = 2147483648
limit_request = 8192
limit_time_cpu = 300
limit_time_real = 900
limit_time_real_cron = -1
list_db = True
log_db = True
log_db_level = warning
log_handler = :INFO
log_level = info
logfile = /var/log/odoo/odoo-server.log
longpolling_port = 8092
max_cron_threads = 1
osv_memory_age_limit = False
osv_memory_count_limit = False
pg_path =
pidfile =
proxy_mode = True
reportgz = False
screencasts =
screenshots = /tmp/odoo_tests
server_wide_modules = base,web
smtp_password = False
smtp_port = 25
smtp_server = localhost
smtp_ssl = False
smtp_user = False
syslog = False
test_enable = False
test_file =
test_tags = None
transient_age_limit = 1.0
translate_modules = [all]
unaccent = False
upgrade_path =
without_demo = True
workers = 5
/etc/odoo/odoo-staging.conf
[options]
addons_path = /home/ubuntu/staging/odoo/addons,/home/ubuntu/staging/enterprise,/home/ubuntu/staging/custom
admin_passwd = myAdminPassword
csv_internal_sep = ,
data_dir = /var/lib/odoo/.local/share/Odoo
db_host = localhost
db_maxconn = 64
db_name = False
db_password = myDbPassword
db_port = False
db_sslmode = prefer
db_template = template0
db_user = myDbUser
dbfilter =
demo = {}
email_from = False
geoip_database = /usr/share/GeoIP/GeoLite2-City.mmdb
http_enable = True
http_interface =
http_port = 8079
import_partial =
limit_memory_hard = 2684354560
limit_memory_soft = 2147483648
limit_request = 8192
limit_time_cpu = 300
limit_time_real = 900
limit_time_real_cron = -1
list_db = True
log_db = True
log_db_level = warning
log_handler = :INFO
log_level = info
logfile = /var/log/odoo/odoo-server.log
longpolling_port = 8082
max_cron_threads = 1
osv_memory_age_limit = False
osv_memory_count_limit = False
pg_path =
pidfile =
proxy_mode = True
reportgz = False
screencasts =
screenshots = /tmp/odoo_tests
server_wide_modules = base,web
smtp_password = False
smtp_port = 25
smtp_server = localhost
smtp_ssl = False
smtp_user = False
syslog = False
test_enable = False
test_file =
test_tags = None
transient_age_limit = 1.0
translate_modules = [all]
unaccent = False
upgrade_path =
without_demo = True
workers = 3
这两个文件必须保存在哪里? nginx 中是否需要配置其他设置? 亲切的问候