登录 立即注册

首页 > 绿虎论坛 > 建站 > 讨论/求助 (发帖)

标题: typecho+nginx 开启伪静态后访问后台404

作者: @Ta

时间: 2023-02-21

点击: 4913

如题,很奇怪,开启伪静态之后通过日志看到,所有请求都被重定向到index.php,同样的配置在宝塔可以跑,移植到我的docker里就不行了,贴上我的配置:

server
{
    listen 80;
    server_name blog.le520.cn;
    index index.php index.html index.htm default.php default.htm default.html;
    root /app;

    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #SSL-END

    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END

    #PHP-INFO-START  PHP引用配置,可以注释或修改
    location ~ [^/]\.php(/|$)
    {
        try_files $uri =404;
        fastcgi_pass  typecho:9000;
        fastcgi_index index.php;
        include /etc/nginx/conf/fastcgi.conf;
        include /etc/nginx/conf/pathinfo.conf;
    }

    #PHP-INFO-END

    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    location / {
        try_files $uri $uri/ /index.php?$args;
        if (!-e $request_filename) {
            rewrite ^/(.*)$ /index.php/$1 last;
        }
    }
    #REWRITE-END

    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log /dev/null;
        access_log /dev/null;
    }

    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log /dev/null;
        access_log /dev/null;
    }
    access_log  /var/logs/wwwlogs/blog.log;
    error_log  /var/logs/wwwlogs/blog.error.log;
}

fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

pathinfo.conf:

set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
		set $real_script_name $1;
		set $path_info $2;
 }
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;

小米8 Explore Edition (透明色)


[隐藏样式|查看源码]


『回复列表(1|隐藏机器人聊天)』

1.

找到问题了,似乎nginx在进行-e判断的时候是在本地读取的,我的nginx和typecho不在同一个docker,所以我应该要把/app文件夹也挂载在nginx的容器里,这样一来看起来好奇怪啊
小米8 Explore Edition (透明色)

(/@Ta/2023-02-21 11:26//)

回复需要登录

12月26日 02:26 星期四

本站由hu60wap6华为CPU驱动

备案号: 京ICP备18041936号-1