Pyramid のリクエスト URL に関する問題で立ち往生しています。ここで、request.static_url
とrequest.application_url
は 2 つの識別可能な容疑者です。
Pyramid で生成されたリクエスト URL には、Web ホストに配置したときに何らかの形でビュー URL が含まれていますが、ローカルではpserve
.
例えば:
config.add_route('signin','/view/signin')
Mako テンプレートの内部
私は持っている:
href="${request.static_url('project:static/blueprint/css/screen.css')}"
(を使用してpserve
)表示する必要があります:
href="http://www.site.com/static/blueprint/css/screen.css"
代わりに次のように表示されます。
href="http://www.site.com/view/signin/static/blueprint/css/screen.css"
もう 1 つの例は、フロント ページの URL に表示されるものです。
src = "http://www.site.com/static/img/foo.jpg"
代わりに、次のように表示されます。
src = "http://www.site.com//static/img/foo.jpg"
現在、VPS サーバーで nginx 0.8.53 + Phusion Passenger 2.2.15 を使用して Pyramid 1.3 + Mako テンプレートを実行しています。
これは も同じrequest.application_url
です。ビューのコードで、私は dict ( url = request.application_url + '/view/signin'
)を送信しました
フォームの URL は次のように表示されます。
action="http://www.site.com/view/signin"
代わりに、次のように表示されます。
action="http://www.site.com/view/signin/view/signin"
http://wiki.pylonshq.com/display/pylonscookbook/Running+Pylons+with+NGINXの nginx 設定の一部をコピーしました。
特に:
#site runs on Pylons
location / {
include /usr/local/nginx/conf/proxy.conf;
proxy_pass http://127.0.0.1:8080;
proxy_redirect default;
}
およびproxy.conf:
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
触れたくないものとして、私が放っておいた他のもの。
サーバー上の nginx.conf は次のようになります。(私はPHPを使用していませんが、それは私が触れたくないものです).
誰かが / でアプリケーションを提供/マウントすることを提案しましたが、その方法がわかりません。
server {
listen <ip>:80;
server_name site.com www.site.com;
access_log /<path>/access.log combined;
error_log /<path>/error.log error;
root /home/<path>/public;
index index.html index.htm index.php index.php5;
include /home/<path>/nginx/site.com/*;
# No mirrors - using strict redirects
#if ($http_host != site.com) {
rewrite ^(.*)$ http://site.com$1 permanent;
#}
autoindex on;
passenger_enabled on;
passenger_base_uri /;
# Disallow access to config / VCS data
location ~* /\.(ht|svn) {
deny all;
}
#site runs on Pylons
location / {
include /<path to conf file>/proxy.conf;
proxy_pass http://127.0.0.1:8080;
proxy_redirect default;
}
# Statistics
location /stats/ {
alias /home/<path>/html/;
auth_basic "Statistics Area";
auth_basic_user_file /home/<path>/html/.htpasswd;
}
location /doc/analog/ {
alias /usr/share/analog/;
}
# PHPMyAdmin
rewrite ^/dh_phpmyadmin/([^/]*)/(.*)$ /dh_phpmyadmin/$2;
location /dh_phpmyadmin/ {
alias /dh/web/phpmyadmin/;
}
location ~ /dh_phpmyadmin/(.+)\.php {
alias /dh/web/phpmyadmin/;
fastcgi_param SERVER_PORT 80;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include /dh/nginx/etc/fastcgi_params;
set $relpath "index.php";
if ($uri ~ ^/dh_phpmyadmin/(.+)$) {
set $relpath $1;
}
fastcgi_param SCRIPT_FILENAME /dh/web/phpmyadmin/$relpath;
fastcgi_pass unix:/home/<path>/.php.sock;
}
# PHP
location ~* \.(php|php5|php4)($|/) {
fastcgi_param SERVER_PORT 80;
fastcgi_split_path_info ^(.+\.(?:php|php5|php4))(/.*)$;
if (!-e $document_root$fastcgi_script_name) {
return 404;
}
include /dh/nginx/etc/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/home/<path>/.php.sock;
#pragma php_launch <path>
}
}