nginx替代指数不起作用

时间:2015-06-12 14:20:08

标签: php nginx

尝试将login.php或/ login设置为转到子域时的索引页面,但我得到的只是一个空白页。

下面的配置:

server {
    listen       80;
    server_name  *.domain.org;

    root   /var/www/html/domain.org/public;
    index login login.php index.php index.html index.htm;

    location ~* \.(css|js|png|woff2|woff|ttf|jpg|jpeg|gif|ico)$ {}

    location = / {
      index login.php;
    }

    location / {
        try_files $uri $uri.php login;
        rewrite ^(.*)$ $uri.php;
    }

    error_page 404 404;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

1 个答案:

答案 0 :(得分:0)

它对我有用:

server {
    listen       80;
    server_name  *.domain.org;

    root   /var/www/html/domain.org/public;
    index index.php index.html index.htm;

    location ~* \.(css|js|png|woff2|woff|ttf|jpg|jpeg|gif|ico)$ {}

    location / {
      index login.php;
    }

    error_page 404 404;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

如果仍然无法正常工作,请尝试将日志记录添加到服务器指令,看看出了什么问题:

error_log /var/www/html/domain.org/public/nginx-error.log;
access_log /var/www/html/domain.org/public/nginx-access.log;