RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 665808
Accepted
ruslik
ruslik
Asked:2020-05-14 19:30:43 +0000 UTC2020-05-14 19:30:43 +0000 UTC 2020-05-14 19:30:43 +0000 UTC

Nginx 重定向到静态页面

  • 772

告诉我如何重定向到某些页面 有一个站点,有 nginx nginx 设置

location / {

        location ~ [^/]\.ph(p\d*|tml)$ {
                try_files /does_not_exists @php;
        }

        location / {
                try_files $uri /index.html;
        }

    }

该站点在 ajax 上——也就是说,所有请求都转到 index.html,并且 js 已经处理了哈希并给出了某些内容。

有一个php文件要发送到邮件

如果请求是http://site.ru/prices?_escaped_fragment_=则返回其特定目录的页面,例如 /static/prices.html

http://site.ru/about?_escaped_fragment_= - /static/about.html

如果已经有设置怎么写这个异常

location / {
                    try_files $uri /index.html;
            }

您可以使用自己的位置对每个页面进行硬编码

无法使用rewrite,因为它不在nginx的初始组装中,没有办法重新构建nginx

server {                                                                                                        
        server_name site.ru www.site.ru;                                                                
        charset off;                                                                                            
        disable_symlinks if_not_owner from=$root_path;                                                          
        index index.html;                                                                                       
        root $root_path;                                                                                        
        set $root_path /var/www/user/data/www/site.ru;                                                      
        access_log /var/www/httpd-logs/site.ru.access.log ;                                                 
        error_log /var/www/httpd-logs/site.ru.error.log notice;                                             
        include /etc/nginx/vhosts-includes/*.conf;                                                              
        gzip on;                                                                                                
        gzip_disable "msie6";                                                                                   
        gzip_types                                                                                              
                application/atom+xml                                                                            
                application/javascript                                                                          
                application/json                                                                                
                application/rss+xml                                                                             
                application/vnd.ms-fontobject                                                                   
                application/x-font-ttf                                                                          
                application/x-web-app-manifest+json                                                             
                application/xhtml+xml                                                                           
                application/xml                                                                                 
                font/opentype                                                                                   
                image/svg+xml                                                                                   
                image/x-icon                                                                                    
                image/png                                                                                       
                image/gif                                                                                       
                image/jpeg                                                                                      
                image/jpg                                                                                       
                text/css                                                                                        
                text/plain                                                                                      
                text/x-component;                                                                               

        location /about$ {                                                                                          

        if ($args ~* "_escaped_fragment_") {                                                                    
            set $args "";                                                                                       

            rewrite ^/.* http://yandex.ru permanent;                                                            
        }                                                                                                       
        }                                                                                                           

        location /prices$ {                                                                                         
        if ($args ~* "_escaped_fragment_") {                                                                    
            set $args "";                                                                                       
            rewrite ^/.* http://yandex.ru permanent;                                                            
        }                                                                                                       
        }                                                                                                           

        location / {                                                                                            

        location ~ [^/]\.ph(p\d*|tml)$ {                                                                        
                try_files /does_not_exists @php;                                                                
        }                                                                                                       

            location / {                                                                                        
                try_files $uri /index.html;                                                                     
        }                                                                                                       

        }                                                                                                           

        location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|woff)$ {            
            expires 30d;                                                                                    
            etag on;                                                                                        
        }                                                                                                       


    location @fallback {                                                                                    
    }                                                                                                       

        location @php {                                                                                         

                fastcgi_index index.php;                                                                        
                fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@site.ru
";                                                                                                              
                fastcgi_pass unix:/var/www/php-fpm/user.sock;                                                   
                fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;                                       
                try_files $uri =404;                                                                            
                include fastcgi_params;                                                                         
        }                                                                                                       
        ssi on;                                                                                                 
        listen xxx.xxx.xxx.xxx:80;                                                                               
}
nginx
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    KAGG Design
    2020-05-14T22:39:47Z2020-05-14T22:39:47Z

    将以下代码粘贴到示例中您所在位置之前的服务器部分:

    # site.ru/about?_escaped_fragment_= -> site.ru/static/about.html    
    location /about$ {
        if ($args ~* "_escaped_fragment_") {
            set $args "";
            rewrite ^/.* http://site.ru/static/about.html permanent;
        }
    }       
    
    # site.ru/prices?_escaped_fragment_= -> site.ru/static/prices.html  
    location /prices$ {
        if ($args ~* "_escaped_fragment_") {
            set $args "";
            rewrite ^/.* http://site.ru/static/prices.html permanent;
        }
    }       
    

    根据添加到问题中的代码,这是完整的服务器部分:

    server {
        listen 80;
        server_name so-665808.kagg.eu;
        charset off;
        set $root_path /var/www/so-665808;
        disable_symlinks if_not_owner from=$root_path;
        root $root_path;
        index index.html;
    
        #access_log /var/www/httpd-logs/site.ru.access.log;
        #error_log /var/www/httpd-logs/site.ru.error.log notice;
        #include /etc/nginx/vhosts-includes/*.conf;
    
        gzip on;
        gzip_disable "msie6";
        gzip_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon image/png image/gif image/jpeg image/jpg text/css text/plain text/x-component;
    
        location ~* /about {
            if ($args ~* "_escaped_fragment_") {
                set $args "";
                rewrite ^/.* http://so-665808.kagg.eu/static/about.html permanent;
            }
        }
    
        location ~* /prices {
            if ($args ~* "_escaped_fragment_") {
                set $args "";
                rewrite ^/.* http://so-665808.kagg.eu/static/prices.html permanent;
            }
        }
    
        location / {
            location ~ [^/]\.ph(p\d*|tml)$ {
                try_files /does_not_exists @php;
            }
            location / {                                                                                        
                try_files $uri /index.html;
            }
        }
    
        location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|woff)$ {
            expires 30d;
            etag on;
        }
    
        location @fallback {
        }
    
        location @php {                                                                                         
            fastcgi_index index.php;
            fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@site.ru";                                                                                                              
            fastcgi_pass unix:/var/www/php-fpm/user.sock;
            fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
            try_files $uri =404;
            include fastcgi_params;
        }   
    
        ssi on;
    }
    

    有日志的行被注释掉了,因为我没有这样的文件夹,也不影响什么。注释掉了include /etc/nginx/vhosts-includes/*.conf;——我不知道里面有什么。

    我上面的代码发生了很大变化(仅在位置部分)- 它在 WordPress 测试站点上运行,并且还有我自己的重定向。

    已经为测试创建了一个特殊站点so-665808.kagg.eu。它包含三个文件:

    http://so-665808.kagg.eu/index.html
    http://so-665808.kagg.eu/static/about.html
    http://so-665808.kagg.eu/static/prices.html
    

    输入地址时

    http://so-665808.kagg.eu/about?_escaped_fragment_
    

    有一个过渡到

    http://so-665808.kagg.eu/static/about.html
    

    输入地址时

    http://so-665808.kagg.eu/prices?_escaped_fragment_
    

    有一个过渡到

    http://so-665808.kagg.eu/static/prices.html
    

    查看。

    • 2

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    Python 3.6 - 安装 MySQL (Windows)

    • 1 个回答
  • Marko Smith

    C++ 编写程序“计算单个岛屿”。填充一个二维数组 12x12 0 和 1

    • 2 个回答
  • Marko Smith

    返回指针的函数

    • 1 个回答
  • Marko Smith

    我使用 django 管理面板添加图像,但它没有显示

    • 1 个回答
  • Marko Smith

    这些条目是什么意思,它们的完整等效项是什么样的

    • 2 个回答
  • Marko Smith

    浏览器仍然缓存文件数据

    • 1 个回答
  • Marko Smith

    在 Excel VBA 中激活工作表的问题

    • 3 个回答
  • Marko Smith

    为什么内置类型中包含复数而小数不包含?

    • 2 个回答
  • Marko Smith

    获得唯一途径

    • 3 个回答
  • Marko Smith

    告诉我一个像幻灯片一样创建滚动的库

    • 1 个回答
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Алексей Шиманский 如何以及通过什么方式来查找 Javascript 代码中的错误? 2020-08-03 00:21:37 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    user207618 Codegolf——组合选择算法的实现 2020-10-23 18:46:29 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5