我在服务器上安装了 Metabase 作为服务并启动了它,但 Nginx 配置出现问题。我在项目中使用 Laravel Forge,我需要更改 Nginx 配置才能访问元数据库。
我当前的默认配置文件如下:
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/default/before/*;
server {
listen 80;
listen [::]:80;
server_name x.x.x.x;
server_tokens off;
root /home/forge/default/public;
# FORGE SSL (DO NOT REMOVE!)
# ssl_certificate;
# ssl_certificate_key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
ssl_dhparam /etc/nginx/dhparams.pem;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/default/server/*;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/default-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/default/after/*;
根据元数据库文档,添加以下语句我应该能够访问元数据库:
# sample nginx.conf
# proxy requests to Metabase instance
server {
listen 80;
listen [::]:80;
server_name your.domain.com;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
当我使用如下配置添加 proxy_pass 时,服务器失败:当我尝试访问端口 3000 时,它返回 502 Bad Gateway 错误和连接超时。
location / {
try_files $uri $uri/ /index.php?$query_string;
proxy_pass http://127.0.0.1:3000;
}
我应该在 nginx 配置中更改什么才能访问元数据库?任何帮助将不胜感激
对于其他不了解系统的人,我已经封锁了端口。
要查看端口 3000 是否打开,请使用
ufw status
.
如果没有出现,请使用
打开端口sudo ufw allow 3000
就是这样,现在可以工作了