1

如果访问者在地址中使用小写或大写,我正在尝试将我的 Nginx 服务器设置为 igonre。例如,我希望 www.mydomain.com/section 和 www.mydomain.com/Section 都指向同一个目录。

我搜索了很多,看看我是否可以通过 vhost 配置来做到这一点,但我找不到。

任何人?

我的 VHost 配置是这样的:

server {
## Your website name goes here.
server_name server.com;
## Your only path reference.
root /var/www/citeu;
listen 80;
client_max_body_size 40M;
## This should be in your http block and if it is, it's not needed here.
index index.php index.htm index.html;

include conf.d/drop;

    location / {
            # This is cool because no php is touched for static content
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location ~ \.php$ {
        fastcgi_buffers 4 256k;
        fastcgi_buffer_size 128k;
        fastcgi_intercept_errors on;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
        fastcgi_max_temp_file_size 50M;


    }

        # BEGIN W3TC Page Cache cache
location ~ /wp-content/w3tc/pgcache.*html$ {
    add_header Vary "Accept-Encoding, Cookie";
}

location ~ /wp-content/w3tc/pgcache.*gzip$ {
    gzip off;
    types {}
    default_type text/html;
    add_header Vary "Accept-Encoding, Cookie";
    add_header Content-Encoding gzip;
}
# END W3TC Page Cache cache
# BEGIN W3TC Browser Cache
gzip on;
gzip_types text/css application/x-javascript text/x-component text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location ~ \.(css|js|htc)$ {
}
location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
}
location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
}
# END W3TC Browser Cache
# BEGIN W3TC Page Cache core
rewrite ^(.*\/)?w3tc_rewrite_test$ $1?w3tc_rewrite_test=1 last;
set $w3tc_rewrite 1;
if ($request_method = POST) {
    set $w3tc_rewrite 0;
}
if ($query_string != "") {
    set $w3tc_rewrite 0;
}
if ($http_host !~ "server.com") {
    set $w3tc_rewrite 0;
}
set $w3tc_rewrite3 1;
if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|\/feed\/|wp-.*\.php|index\.php)") {
    set $w3tc_rewrite3 0;
}
if ($request_uri ~* "(wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php)") {
    set $w3tc_rewrite3 1;
}
if ($w3tc_rewrite3 != 1) {
    set $w3tc_rewrite 0;
}
if ($http_cookie ~* "(comment_author|wp\-postpass|wordpress_\[a\-f0\-9\]\+|wordpress_logged_in)") {
    set $w3tc_rewrite 0;
}
if ($http_user_agent ~* "(W3\ Total\ Cache/0\.9\.2\.4)") {
    set $w3tc_rewrite 0;
}
set $w3tc_ua "";
set $w3tc_ref "";
set $w3tc_ssl "";
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
    set $w3tc_enc _gzip;
}
set $w3tc_ext "";
if (-f "$document_root/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl.html$w3tc_enc") {
    set $w3tc_ext .html;
}
if ($w3tc_ext = "") {
  set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
    rewrite .* "/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl$w3tc_ext$w3tc_enc" last;
}
# END W3TC Page Cache core

}

4

3 回答 3

1

我还找到了另一个临时解决方案。

我用了:

 location ~ /Folder {
        rewrite ^/([^/]*)(.*)$ /folder;}

以防万一访问者想要访问我希望他访问的特定文件夹,但输入与原始文件夹不同的字母大小写。它远非完美的解决方案,但我会在弄清楚如何正确使用模块时使用。

于 2013-03-22T10:41:21.530 回答
0

您的问题不在于主机名,而在于位置块和文件名。

在位置块方面,您可以使用此运算符进行不区分大小写的匹配~*

大多数文件系统都区分大小写,因此如果您提供的文件是真实的……您可能会遇到问题。

大多数人会这样做:

  • 确保一切都是小写
  • 使用 try_files 文件指令失败到一个简单地重定向到一个完全小写的 url 的 php 脚本

有一个第三方库可以进行小写字符串转换(http://wiki.nginx.org/3rdPartyModules

于 2013-03-21T22:49:40.037 回答
0

以下内容对我有用,以大写或小写字母打开(ibeacons.html)

 location ~* /ibeacons.html {

 try_files $uri $uri/ /ibeacons.html;
于 2014-10-09T12:41:17.290 回答