2010-11-24 18 views
0

我在開發服務器上用nginx替換lighttpd。我使用PHP和SSL工作,但我很難被簡單的重寫。我需要從nginx重寫神祕 - 複製主機名並丟失https

http[s]://dev.foo.com/signup/123456 

重寫URL到

http[s]://dev.foo.com/signup/index.php?attcode=123456 

規則我現在用的就是:

rewrite ^/signup/([0-9]+)$ /signup/index.php?attycode=$1 last; 

我試圖在這許多變化,四處移動它,把它裏面一個位置塊。會發生什麼是URL被重寫爲:

http://dev.foo.com/dev.foo.com/signup/123456 

主機名被插入,它似乎總是丟失https並轉到http。

我的nginx.com服務器部分如下。我已經閱讀並重新閱讀nginx文檔(因爲它們是)並且搜索了nginx郵件列表,但是我沒有試過解決這個問題。

Ubuntu 8.0.4 LTS萬一有問題。

謝謝。


server { 
    listen  80; 
    listen  443 default ssl; 
    server_name dev.foo.com dev.bar.com localhost; 
    root  /var/www/foo; 
    index  index.php index.html; 
    # ssl cert stuff omitted 
    charset utf-8; 
    access_log /var/log/www/dev.access.log main; 

    location ~ /\. { 
     deny all; 
    } 

    location ~* ^.+\.(inc|tpl|sql|ini|bak|sh|cgi)$ { 
     deny all; 
    } 

    location ~* ^/(scripts|tmp|sql)/ { 
     deny all; 
    } 

    rewrite ^/robots.txt$   /robots_nocrawl.txt break; 
    rewrite ^/signup/([0-9]+)$ /signup/index.php?attycode=$1 last; 

    location/{ 
     try_files $uri $uri/ /error_404.php; 
    } 

    location ~ \.php$ { 
     fastcgi_pass localhost:51115; 
     fastcgi_index index.php; 
     fastcgi_intercept_errors on; 
     include fastcgi_params; 
     fastcgi_param SERVER_NAME  $http_host; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 

    error_page 404    /error_404.php; 
} 

回答

0

不要把HTTP和HTTPS在同一服務器塊。將它們分成兩個幾乎相同的服務器塊,一個用於HTTP,一個用於HTTPS。否則你會混淆各種Nginx內部。

+0

nginx文檔至少暗示在單個服務器塊中組合http和https是可以的。請參閱http://www.nginx.org/en/docs/http/configuring_https_servers.html – gregjor 2010-11-24 21:28:07