我有一个具有以下规则的工作 nginx 实例。但是我很难将所有请求指向 domain.com/ghost

我尝试将 location / {} 块修改为 location /ghost/ {} 但没有成功。我刚从 ghost 应用程序中得到 404。有什么建议么?

server {
    listen         80;
    server_name domain.com;
    root /home//user/ghost/;
    index index.php;

   # if ($http_host != "domain.com") {
   #      rewrite ^ http://domain.com$request_uri permanent;
   # }

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:2368;
    }

    location ~* \.(?:ico|css|js|gif|jpe?g|png|ttf|woff)$ {
        access_log off;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, mustrevalidate, proxy-revalidate";
        proxy_pass http://127.0.0.1:2368;
    }

    location = /robots.txt { access_log off; log_not_found off; }
    location = /favicon.ico { access_log off; log_not_found off; }

    location ~ /\.ht {
            deny all;
    }
}

最佳答案

我正在使用 regexp location 指令进行类似的代理设置。这是缩小的配置文件:

worker_processes  1;
pid               /path/to/file.pid;
worker_priority   15;

events {
    worker_connections 512;
    accept_mutex        on;
}

http {
    server {
        error_log   /path/to/log/error.log error;
        listen      127.0.0.1:9000;
        server_name example.com;

        location ~* (/ghost) {
           expires epoch;
           proxy_no_cache 1;
           proxy_pass http://localhost:1234;
        }

        location / {
            proxy_pass http://localhost:1234;
        }
    }
}

关于Nginx - 使用/subfolder 重定向反向代理 Ghost 博客,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20077208/

10-13 00:38