歡迎您光臨本站 註冊首頁

nginx為什麼在二級目錄訪問的時候要加/才能訪問到(已解決)

nginx為什麼在二級目錄訪問的時候要加/才能訪問到
比如http://www.domain.com/dir
要這樣http://www.domain.com/dir/才能訪問到
不加最後那個/無法訪問。

配置文件

user  vmail vmail;
worker_processes  10;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  51024;
    use kqueue;
}


http {
    include       conf/mime.types;
    include       conf/fastcgi.conf;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] $request '
    #                  '"$status" $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    client_header_timeout  3m;

    client_body_timeout    3m;
    send_timeout           3m;

    client_header_buffer_size    1k;
    large_client_header_buffers  4 4k;

    gzip on;
    gzip_min_length  1100;
    gzip_buffers     4 8k;
    gzip_types       text/plain;

    output_buffers   1 32k;
    postpone_output  1460;

    sendfile         on;
    tcp_nopush       on;
    tcp_nodelay      on;
    send_lowat       12000;

    keepalive_timeout  75 20;


    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm index.php;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    root   html;
        #}

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        conf/fastcgi_params;
        }

        location /NginxStatus {
            stub_status             on;
            access_log              on;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

[ 本帖最後由 scyzxp 於 2008-2-1 14:13 編輯 ]
《解決方案》

我用apache和nginx做了對比試驗
在二級目錄訪問的時候,apache是IE自動把/加上去的,而nginx不能做到。
可以參考一下這個網站關於Location的部分內容:
http://wiki.codemongers.com/NginxHttpCoreModule#location

也許能找到答案,希望對你有幫助^_^
《解決方案》

原帖由 adu119 於 2008-2-1 11:52 發表 http://bbs.chinaunix.net/images/common/back.gif
我用apache和nginx做了對比試驗
在二級目錄訪問的時候,apache是IE自動把/加上去的,而nginx不能做到。
可以參考一下這個網站關於Location的部分內容:
http://wiki.codemongers.com/NginxHttpCoreModule#lo ...

首先感謝你,我看了半天還是沒有找到答案,希望有人能找到解記辦法
《解決方案》

原帖由 scyzxp 於 2008-2-1 13:47 發表 http://bbs.chinaunix.net/images/common/back.gif


首先感謝你,我看了半天還是沒有找到答案,希望有人能找到解記辦法


自己解決了。多謝各位的關注
《解決方案》

如何解決的說說

如何解決的?
《解決方案》

我也想知道,大蝦,回個貼啊
《解決方案》

怎麼解決的?
《解決方案》

默認配置當你訪問http://abc.example.com/dir 時不會加」/」

常見做法

      if (-d $request_filename){
  rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
      }


更佳的替代方法

optimize_server_names off;#優化伺服器名稱:關
server_name_in_redirect off;#伺服器名稱重定向:關

http://wiki.codemongers.com/NginxHttpCoreModule#optimize_server_names

[火星人 ] nginx為什麼在二級目錄訪問的時候要加/才能訪問到(已解決)已經有657次圍觀

http://coctec.com/docs/service/show-post-27544.html