【问题标题】:nginx - Friendly URL's in directorynginx - 目录中的友好 URL
【发布时间】:2017-05-30 20:45:24
【问题描述】:

我将友好 URL 从 Apache 移动到 nginx,但我遇到了问题。我希望友好 URL 仅在子目录 sgforum 内有效。

在 PHP 中,我收到的地址为:127.0.0.1/sgforum/index127.0.0.1/sgforum/member 等等。

当我继续 127.0.0.1/sgforum/ - 它有效,但是当我给 member (127.0.0.1/sgforum/member ) 或 index,它将文件下载到我的计算机,而不是使用 php 打开。

这是我的 /etc/nginx/sites-available/default 文件:

server {
    listen 80 default_server;
    #listen [::]:80 default_server;

    root /home/ariel/workspace;

    index index.php index.html;

    server_name _;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    # FRIENDLY URLS
    location /sgforum/ {
        if (!-e $request_filename){
            rewrite ^/sgforum/(.*)$ /sgforum/index.php break;
        }
    }

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

【问题讨论】:

    标签: php linux nginx friendly-url


    【解决方案1】:

    我改变了它,终于可以正常工作了。

    # FRIENDLY URLS
    location /sgforum/ {
        try_files $uri $uri/ /sgforum/index.php;
    }
    

    【讨论】:

    • 有一个类似的问题,这对我有用。谢谢。
    【解决方案2】:

    尝试改变

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

    【讨论】:

    • 现在我输入的任何短语都有 404,但仍将正确的 URL 保存为 sgforum/member 到文件成员。
    【解决方案3】:

    您必须为成员文件夹设置位置

    【讨论】:

    • member - 不是目录,它是在 PHP $_SERVER['REQUEST_URI'] 中回答并选择特定操作的参数。
    • 当你下载一个文件意味着你必须调整 php-fpm 设置
    • @MeiramChuzhenbayev,您能否将您的两个答案作为一个完整的答案发布?
    猜你喜欢
    • 2015-06-02
    • 2014-07-26
    • 1970-01-01
    • 2013-06-08
    • 2016-11-28
    • 1970-01-01
    • 2016-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多