1. 程式人生 > >nginx重啟失敗

nginx重啟失敗

/usr/local/webserver/nginx/sbin/nginx -t

出現如下錯誤

nginx: [alert] mmap(MAP_ANON|MAP_SHARED, 10737418240) failed (12: Cannot allocate memory)

nginx: configuration file /usr/local/webserver/nginx/conf/nginx.conf test failed

nginx的cache採用mmap實現,快取區的大小不能超過剩餘的記憶體大小和swap值的總和。

Apache Rewrite 規則:
RewriteRule  ^/html/tagindex/([a-zA-Z]+)/.*$ /$1/ [R=301,L]


Nginx Rewrite 規則:
rewrite  ^/html/tagindex/([a-zA-Z]+)/.*$ http://$host/$1/  permanent;

Apache Rewrite 規則:
RewriteRule  ^/user/login/$ /user/login.php?login=1&forward=http://%{HTTP_HOST}  [L]


Nginx Rewrite 規則:
rewrite  ^/user/login/$ /user/login.php?login=1&forward=http://$host   last;

Apache與Nginx Rewrite 規則的一些功能相同或類似的指令、標記對應關係:


Apache的RewriteCond指令對應Nginx的if指令;
Apache的RewriteRule指令對應Nginx的rewrite指令;
Apache的[R]標記對應Nginx的redirect標記;
Apache的[P]標記對應Nginx的last標記;
Apache的[R,L]標記對應Nginx的redirect標記;
Apache的[P,L]標記對應Nginx的last標記;
Apache的[PT,L]標記對應Nginx的last標記;

nginx多條件rewrite例項

Nginx Rewrite 規則:
if ($host ~* ^(.*?)\.domain\.com$)
{
set $var_wupin_city $1;
set $var_wupin '1';
}
if ($host ~* ^qita\.domain\.com$)
{
set $var_wupin '0';
}
if (!-f $document_root/market/$var_wupin_city/index.htm)
{
set $var_wupin '0';
}
if ($var_wupin ~ '1')
{
rewrite ^/wu/$ /market/$var_wupin_city/index.htm last;
}