nginx& https重定向,网页主题/图像/格式无法正常工作!!怎么了?

时间:2013-11-20 14:54:38

标签: http redirect nginx https

可能有些专家可以修改我的剧本了。我是菜鸟,并试图设置nginx& drupal在我的本地电脑上。它工作正常,除了HTTPS重定向,并收到错误消息“端口80 443 HTTPS请求等等。”

我在这个论坛上发现,添加几行“proxy_pass”编码(下面)可以重定向,所以我做到了。多数民众赞成!但现在删除了网站主题和格式。我只能看到带有链接和文本的白页。有人能告诉我一些光吗?

  server {
        listen          80;
        server_name     localhost;
    return 301  https://$host$request_uri;
    #rewrite ^ https://$host$request_uri? permanent;
}
server {
    listen               443;
        server_name  localhost;
    ssl                  on;
    ssl_certificate      /srv/www/sslcerts/cdb.crt;
    ssl_certificate_key  /srv/www/sslcerts/cdb.key;
        error_page 497  https://$host:$server_port$request_uri;

    location / {
        root   /srv/www/cdb;
        index  index.php;
    #try_files   $uri $uri/ /index.php;
    try_files $uri @rewrite;
##ADDED LATER & theme not working
            proxy_pass http://localhost:80;
            proxy_redirect off;
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Ssl on;
        proxy_set_header  X-Forwarded-Proto  https;
    }

location ~ ^/sites/.*/files/styles/ {
               try_files $uri @rewrite;
    }

location ~ \.php$ {
    root        /srv/www/cdb/;
        fastcgi_pass   127.0.0.1:9000;
    #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #fastcgi_in;tercept_errors on;
        fastcgi_param  SCRIPT_FILENAME  /srv/www/cdb$fastcgi_script_name;
        fastcgi_buffer_size          128k;
        fastcgi_buffers            256 4k;
        fastcgi_busy_buffers_size    256k;
        fastcgi_temp_file_write_size 256k;
        include        fastcgi_params;
    }

if ($request_method !~ ^(GET|HEAD|POST)$ ) {
         return 444;
    }

if ($http_user_agent ~* LWP::Simple|BBBike|wget|libwww-perl) {
            return 403;
    }

if ($http_user_agent ~* msnbot|scrapbot|Purebot|Baiduspider|Lipperhey|Mail.Ru) {
            return 403;
    }

if ( $http_referer ~* (babes|forsale|girl|jewelry|love|nudit|organic|poker|porn|sex|teen|viagra|nude|casino) )
     {
         return 403;
    }

location /images/ {
  valid_referers none blocked www.example.com example.com;
   if ($invalid_referer) {
     return   403;
    }
      }

location @rewrite {
    rewrite ^ /index.php;
    }

#location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
 #               expires max;
  #              log_not_found off;
   #     }

location ~* /(images|cache|media|logs|tmp)/.*.(php|pl|py|jsp|asp|sh|cgi)$ {
    return 403;
    error_page 403 /403_error.html;
    }

location ~ /\. {
        access_log off;
        log_not_found off;
        deny  all;
    }
}

2 个答案:

答案 0 :(得分:0)

您是否尝试过更改

location @rewrite {
    rewrite ^ /index.php;
}

 location @rewrite {
     rewrite ^/(.*)$ /index.php?q=$1;
 }

我认为如果您使用干净的网址,此配置会有效。

答案 1 :(得分:0)

最后工作了:) 这个脚本适用于Clean URL& http重定向到https端口

  server {
        listen          80;
        server_name     localhost;
        return 301  https://$host$request_uri;
    }
    server {
        listen               443;
        server_name  localhost;
        ssl                  on;
        ssl_certificate      /srv/www/sslcerts/cdb.crt;
        ssl_certificate_key  /srv/www/sslcerts/cdb.key;
        error_page 497  https://$host:$server_port$request_uri;

    location / {
        root   /srv/www/cdb;
        index  index.php;
        try_files $uri @rewrite;
        }

    location ~ ^/sites/.*/files/styles/ {
        try_files $uri @rewrite;
        }

    location ~ \.php$ {
        root        /srv/www/cdb/;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param  SCRIPT_FILENAME  /srv/www/cdb$fastcgi_script_name;
        fastcgi_buffer_size          128k;
        fastcgi_buffers            256 4k;
        fastcgi_busy_buffers_size    256k;
        fastcgi_temp_file_write_size 256k;
        include        fastcgi_params;
        }

    if ($request_method !~ ^(GET|HEAD|POST)$ ) {
        return 444;
        }

    if ($http_user_agent ~* LWP::Simple|BBBike|wget|libwww-perl) {
        return 403;
        }

    if ($http_user_agent ~* msnbot|scrapbot|Purebot|Baiduspider|Lipperhey|Mail.Ru) {
        return 403;
        }

    if ( $http_referer ~* (babes|forsale|girl|jewelry|love|nudit|organic|poker|porn|sex|teen|viagra|nude|casino) ) {
        return 403;
        }

    location /images/ {
      valid_referers none blocked www.example.com example.com;
    if ($invalid_referer) {
        return   403;
        }
          }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
        }

    location ~* /(images|cache|media|logs|tmp)/.*.(php|pl|py|jsp|asp|sh|cgi)$ {
        return 403;
        error_page 403 /403_error.html;
        }

    location ~ /\. {
        access_log off;
        log_not_found off;
        deny  all;
        }
    }