nginx:url不会重定向

时间:2014-08-27 12:14:24

标签: redirect nginx configuration

我想要png url&#39>

http://www.imvuoutfits.com/hpv/images/declined.png  http://www.imvuoutfits.com/hpv/images/approved.png

现在指向

http://www.imvuoutfits.com/submit/images/declined.png http://www.imvuoutfits.com/submit/images/approved.png

尊敬。我尝试过使用:

    location ~ /hpv/images {
        rewrite /hpv/images/declined.png http://www.imvuoutfits.com/submit/images/declined.png redirect;
        rewrite /hpv/images/approved.png http://www.imvuoutfits.com/submit/images/approved.png redirect;
    }

我也尝试过:

location /hpv/images/declined\.png {
    rewrite ^/(.+)  "http://www.imvuoutfits.com/submit/images/declined.png" redirect;
}

location /hpv/images/approved\.png {
    rewrite ^/(.+)  "http://www.imvuoutfits.com/submit/images/approved.png" redirect;
}

但不起作用,可能是冲突 - 我不确定,我的整个文件:

server {
    server_name  imvuoutfits.com;
    return       301 http://www.imvuoutfits.com$request_uri;
}

server {
    root /var/www/sedulity;
    index index.php index.html index.htm;

    server_name www.imvuoutfits.com *.imvuoutfits.com;



    access_log  /var/log/nginx/sedulity_access.log;
    #rewrite_log on;
    error_log  /var/log/nginx/sedulity_error.log;
    #error_log  /var/log/nginx/imvu_error.log  notice;
    #error_log  /var/log/nginx/imvu_error.log  info;



    rewrite /wp-admin$ $scheme://$host$uri/ permanent;



    location ~* \.(png|gif|jpg|jpeg|css|js|swf|ico|txt|xml|bmp|pdf|doc|docx|ppt|pptx|zip)$ {
        access_log off;
        expires 30d;
    }



    location / {
        try_files $uri $uri/ /index.php?$args;
        expires 30d; ## Assume all files are cachable
        if ($request_uri ~* "\.(png|gif|jpg|jpeg|css|js|swf|ico|txt|xml|bmp|pdf|doc|docx|ppt|pptx|zip)$") {
            expires max;
        }
    }

    location /submit/try {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/sedulity/submit/try.php;
    }

    location /submit/outfit {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /var/www/sedulity/submit/outfit.php;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }

        proxy_read_timeout 600;
        fastcgi_read_timeout 600;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        #####################
        fastcgi_param imvu_user livindeadgirlx;
        fastcgi_param imvu_pass Xhfd83rh;
        #####################
        fastcgi_param db_host daldb.vpsdime.com;
        fastcgi_param db_user xoxo;
        fastcgi_param db_pass lmiNumkw2nje3;

        fastcgi_param REDIRECT_URL $request_uri; #This solve all my problems :D.
    }

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

    ##########################################

    # Allow access to /wp-admin/ only to a specific IP address
    location ~* wp-admin {
        try_files $uri $uri/ =404;
        allow 127.0.0.1;
        deny all;
    }

    # http://blog.bigdinosaur.org/wordpress-on-nginx/
    # Common deny or internal locations, to help prevent access to not-public areas
    location ~* wp-admin/includes { deny all; }
    location ~* wp-includes/theme-compat/ { deny all; }
    location ~* wp-includes/js/tinymce/langs/.*\.php { deny all; }
    location /wp-content/ { internal; }
    location /wp-includes/ { internal; }
    location ~* wp-config.php { deny all; }

    # Prevent any potentially-executable files in the uploads directory from being executed
    # by forcing their MIME type to text/plain
    location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php|js|swf)$ {
        types { }
        default_type text/plain;
    }

    # Rewrite rules for Wordpress SEO by Yoast
    rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

    # Add trailing slash to */wp-admin requests
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    # Redirect 403 errors to 404 error to fool attackers
    error_page 403 = 404;

    ##########################################

    location ~ /hpv/images {
        rewrite /hpv/images/declined.png http://www.imvuoutfits.com/submit/images/declined.png redirect;
        rewrite /hpv/images/approved.png http://www.imvuoutfits.com/submit/images/approved.png redirect;
    }

    if ($request_uri ~ "^/hpv/upload/server/php/files/(.*)$"){
        rewrite ^/(.+) "http://media.imvuoutfits.com/screenshots/%1" break;
    }



    # BEGIN W3TC Minify core
    rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 last;
    rewrite ^/wp-content/cache/minify/(.+/[X]+\.css)$ /wp-content/plugins/w3-total-cache/pub/minify.php?test_file=$1 last;
    rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last;
    # END W3TC Minify core

    # BEGIN W3TC Browser Cache
    gzip on;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
    # END W3TC Browser Cache

    # BEGIN W3TC CDN
    location ~ \.(ttf|ttc|otf|eot|woff|font.css)$ {
       add_header Access-Control-Allow-Origin "*";
    }
    # END W3TC CDN

}

1 个答案:

答案 0 :(得分:1)

Nginx location是独家的。

因此,您要求进入location ~* \.(png|gif|...并且永远不会到达您添加的新位置。 使其成为嵌套位置。