做题记录了新服务器postgres的安装及访问相关的问题及解决方案。 昨天晚上遇到api接口及前端没发访问的问题。 解决方案:
- 首先需要开通443及80等端口(ubuntu默认是不开启状态)
- 因为项目前后端及API都在一个域名+二级目录部署,所以我再把nginx配置也加到下面。
server {
listen 443 ssl;
server_name aa.com;
ssl_certificate "/root/cert/aa.com.pem";
ssl_certificate_key "/root/cert/aa.com.key";
# 新增:健康检查接口代理
location /health {
proxy_pass http://localhost:3000/health;
proxy_set_header Host $host;
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 $scheme;
}
# 新增:健康检查接口代理
location /scalar {
proxy_pass http://localhost:3000/scalar ;
proxy_set_header Host $host;
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 $scheme;
}
# 全局API代理
location ^~ /api/ {
client_max_body_size 20m;
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
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 $scheme;
}
# admin页面的API代理
location ^~ /dev/api/ {
client_max_body_size 20m;
proxy_pass http://localhost:3000/api/;
proxy_set_header Host $host;
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 $scheme;
}
# admin页面静态文件
location /dev {
alias /var/www/aa/dev;
index index.html;
try_files $uri $uri/ /dev/index.html;
# 静态资源缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
# 主页面
location / {
root /var/www/aa/;
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 80;
server_name aa.com;
root /var/www/aa;
rewrite ^(.*) https://$server_name$1 permanent;
}