【发布时间】:2017-05-30 20:45:24
【问题描述】:
我将友好 URL 从 Apache 移动到 nginx,但我遇到了问题。我希望友好 URL 仅在子目录 sgforum 内有效。
在 PHP 中,我收到的地址为:127.0.0.1/sgforum/index、127.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