相关疑难解决方法(0)

在 Nginx 中提供静态 HTML 文件而不在 url 中扩展

根目录 = /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 从 url 中删除 .php 和 .html 扩展名?

如何在 nginx 中提供 html 文件而不在此别名设置中显示扩展名

webserver nginx httpserver

6
推荐指数
1
解决办法
3813
查看次数

Nginx和处理文件没有扩展名

我试图让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

5
推荐指数
2
解决办法
6479
查看次数

nginx删除.php和.html文件扩展名

我一直在尝试使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)

nginx

4
推荐指数
1
解决办法
2901
查看次数

标签 统计

nginx ×3

httpserver ×1

webserver ×1