nginx - 目录中的友好 URL
nginx - Friendly URL's in directory
我将我的 Friendly URL 从 Apache 移动到 nginx,但我遇到了问题。我想 Friendly 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;
}
}
您必须为成员文件夹设置位置
尝试改变
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;
}
我改了,终于可以正常使用了。
# FRIENDLY URLS
location /sgforum/ {
try_files $uri $uri/ /sgforum/index.php;
}
我将我的 Friendly URL 从 Apache 移动到 nginx,但我遇到了问题。我想 Friendly 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;
}
}
您必须为成员文件夹设置位置
尝试改变
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;
}
我改了,终于可以正常使用了。
# FRIENDLY URLS
location /sgforum/ {
try_files $uri $uri/ /sgforum/index.php;
}