根目录 = /srv/myproject/xyz/main/
在“主”文件夹中,我有几个 *.html 文件,我希望它们都指向一个 url 说/test/(这与目录结构完全不同)
这是我非常基本的 nginx 配置
server {
listen 80;
error_log /var/log/testc.error.log;
location /test/ {
root /srv/myproject/xyz/main/;
#alias /srv/myproject/xyz/main/;
default_type "text/html";
try_files $uri.html ;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我使用简单别名
location /test/ {
alias /srv/myproject/xyz/main/;
}
Run Code Online (Sandbox Code Playgroud)
那么它的工作完美,我的意思是我可以通过http://www.myurl.com/test/firstfile.html等等访问这些html文件
但我不想要那个 html 扩展。
我试图遵循这些线程但没有成功 http://forum.nginx.org/read.php?11,201491,201494
我试图让Nginx处理没有扩展名的php文件(即处理http:// localhost/sample的方式与处理http://localhost/sample.php的方式相同).
这是我的网站配置:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name localhost;
root /var/www;
index index.html index.php;
location ~ \.(hh|php)$ {
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
try_files $uri $uri/ $uri.html @extensionless =404;
}
location @extensionless {
rewrite ^(.*)$ $1.php last;
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知它应该做的伎俩.但是 - 它没有.尝试http:// localhost/sample只是让我到404页面(而http://localhost/sample.php工作正常).
打开调试时,我在日志中看到以下内容:
2015/07/19 15:37:00 [debug] 4783#0: *1 http script var: "/sample"
2015/07/19 15:37:00 [debug] 4783#0: …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使nginx在没有.php或.html扩展名的情况下工作,我需要一些帮助。在此先感谢您的时间!
我尝试了如何使用NGINX从网址中同时删除.php和.html扩展名的解决方案?但是没有效果
这是我当前的nginx配置。它是几个教程的组合,但是可以用。
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts to this file
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# ht
tp://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and …Run Code Online (Sandbox Code Playgroud)