xioyito / NewBee

A elegance, clean Hugo Theme with high interaction for blogger
MIT License
50 stars 17 forks source link

nginx方式部署失败 #19

Closed cappuccino5 closed 1 year ago

cappuccino5 commented 1 year ago

版本cmmit:0ab6ab1fcfbd33fc3b8abccc4e403bf7e1c845a9

hugo.toml 配置: baseURL = 'http://192.168.159.128:28080'

部署方式:nginx+docker

我的nginx配置:

server {
    listen 80;
    server_name  _;
    root /usr/share/nginx/html;

   location /index.html {
        add_header Cache-Control "no-cache, no-store";
    }

   location ~ \.(css|js|gif|jpg|jpeg|png|svg|ico)$ {
        try_files $uri =404;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        access_log /var/log/nginx/web.access.log;
        error_log /var/log/nginx/web.error.log;
        try_files $uri $uri/ /index.html;
    }
}

问题描述: 当我使用nginx docker 的方式部署后,访问http://192.168.159.128:28080 正常 image

但当跳转到文章或者标签返回异常(找不到route);原因是Response Headers的Location返回的地址少了端口号; 请帮检查一下是我的nginx配置问题还是其它原因?

image

cappuccino5 commented 1 year ago

已解决; 看起来是我nginx配置的问题

正确的配置,增加了配置项 absolute_redirect off;

server {
    listen 80;
    absolute_redirect off;
    server_name  _;
    root /usr/share/nginx/html;

   location /index.html {
        add_header Cache-Control "no-cache, no-store";
        proxy_set_header Host $http_host;
    }

   location ~ \.(css|js|gif|jpg|jpeg|png|svg|ico)$ {
        try_files $uri =404;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        access_log /var/log/nginx/web.access.log;
        error_log /var/log/nginx/web.error.log;
        try_files $uri $uri/ index.html;
    }
}