nginx - 目录中的友好URL

时间:2017-01-16 03:49:07

标签: php linux nginx friendly-url

我将我的友情网址从Apache移动到nginx,我遇到了问题。我希望友情网址只能在子目录 sgforum 中使用。

在PHP中,我收到以下地址: 127.0.0.1/sgforum/index 127.0.0.1/sgforum/member 等。

当我继续 127.0.0.1/sgforum / 时 - 它可以正常工作,但是当我提供成员时( 127.0.0.1/sgforum/member )或索引,它会将文件下载到我的计算机上,而不是用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;
    }
}

3 个答案:

答案 0 :(得分:0)

我改变了它,最后按原样运作。

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

答案 1 :(得分:-1)

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

答案 2 :(得分:-1)

尝试更改

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;
    }
相关问题