我正在使用Nginx代理我的Odoo实例,以启用CORS并使用我创建的VueJS应用对其进行查询。 nginx.conf
如下所示:
#user nobody;
worker_processes 1;
# error_log logs/error.log;
# error_log logs/error.log notice;
# error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream odoo {
server 127.0.0.1:8069;
}
server {
listen 443 default;
server_name localhost;
root c:/nginx/html;
index index.html index.htm;
access_log c:/nginx/logs/odoo.access.log;
error_log c:/nginx/logs/odoo.error.log;
proxy_buffers 16 64k;
proxy_buffer_size 128k;
location / {
proxy_pass http://odoo;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
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 https;
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
}
location ~* /web/static/ {
proxy_cache_valid 200 60m;
proxy_buffering on;
expires 864000;
proxy_pass http://odoo;
}
}
}
我想将我的VueJS应用(在端口8080下运行)添加到与一个代理odoo相同的服务器上,位于位置 / vue 下,如下所示:
location / {
// Same as above
}
location ~* /web/static/ {
// Same as above
}
location /vue {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:8080;
}
通过443端口访问odoo可以正常工作,它正在尝试访问抛出空白页的/ vue路由以及以下错误:
我想指出的是,我正在托管通过 vue-cli 3 创建的Vue应用程序的开发版本,其中包括webpack和打字稿支持。 我不打算部署生产版本。
此外,假设我决定构建并部署应用程序,如何将其托管在同一服务器上?