Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have used Linux first. When I used this rewrite code in nginx on windows there were no errors.

But in linux(ubunt-12.04) there are errors. I don't know What is the matter.

------------------------------rewrite code-----------------------------------

rewrite ^/(layouts|m.layouts)/(.+)/(.+).html$ /./index.php last;
rewrite ^/(modules|addons|widgets)/(.+)/(conf|queries|schemas)/(.+).xml$ /./index.php last;

location ~ /(.+)/files/(member_extra_info|attach|cache|faceOff)/(.*)
{
try_files $uri /./files/$2/$3;
}

location ~ /(.+)/(files|modules|widgets|widgetstyles|layouts|m.layouts|addons)/(.*)
{
try_files $uri /./$2/$3;
}

rewrite ^/(rss|atom)$ /./index.php?module=rss&act=$1 last;
rewrite ^/([a-zA-Z0-9_]+)/(rss|atom|api)$ /./index.php?mid=$1&act=$2 last;
rewrite ^/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/(rss|atom|api)$ /./index.php?vid=$1&mid=$2&act=$3 last;
rewrite ^/([0-9]+)/(.+)/trackback$ /./index.php?document_srl=$1&key=$2&act=trackback last;
rewrite ^/([a-zA-Z0-9_]+)/([0-9]+)/(.+)/trackback$ /./index.php?vid=$1&document_srl=$2&key=$3&act=trackback last;
rewrite ^/admin/?$ /./index.php?module=admin last;
rewrite ^/([0-9]+)$ /./index.php?document_srl=$1 last;

location ~ /([a-zA-Z0-9_]+)/?$
{
try_files $uri/ /./index.php?mid=$1$is_args$args;
}

rewrite ^/([a-zA-Z0-9_]+)/([0-9]+)$ /./index.php?mid=$1&document_srl=$2 last;

location ~ /([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/?$
{
try_files $uri/ /./index.php?vid=$1&mid=$2$is_args$args;
}

rewrite ^/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/([0-9]+)$ /./index.php?vid=$1&mid=$2&document_srl=$3 last;
rewrite ^/([a-zA-Z0-9_]+)/entry/(.+)$ /./index.php?mid=$1&entry=$2 last;
rewrite ^/([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/entry/(.+)$ /./index.php?vid=$1&mid=$2&entry=$3 last;

------------------------------rewrite end-----------------------------------

Error message


[emerg] "rewrite" directive is not allowed here in /etc/nginx/conf.d/rewrite.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed

And add etc.conf**


    location ~* ^.+\.(gif|png|jpe?g|ico|bmp)$ {
        access_log off;
        expires 30d;
    }


    location ~* ^.+\.(css|js)$ {
        expires 1h;
    }


    location ~* /((config|db\.inc|_head|lib|common)\.php$|\.(htaccess|htpasswd)$) {
        deny all;
    }


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


    if ($args ~*  "(_zb_path|g4_path|site_path|skin_site_path)=|GLOBALS(=|\[|\%[0-9A-Z]{0,2})|_REQUEST(=|\[|\%[0-9A-Z]{0,2})|(\<|%3C).*script.*(\>|%3E)|base64_encode.*\(.*\)") {
        return 403;
    }


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


    # http error message file
    error_page 401 /error401.htm;
    error_page 403 /error403.htm;
    error_page 404 /error404.htm;
    error_page 405 /error405.htm;
    error_page 406 /error406.htm;
    error_page 412 /error412.htm;
    error_page 500 /error500.htm;
    error_page 501 /error501.htm;
    error_page 502 /error502.htm;
    location ~* ^/((error[0-9]+)\.htm) {
        internal;
        root error;
    }

This error appeared too


[emerg] "location" directive is not allowed here in /etc/nginx/conf.d/etc.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed

share|improve this question
    
Methinks your configuration is too complicated. Why won't a simpler solution do? –  Colin 't Hart Oct 22 '12 at 9:36
    
How to simpler..... That source do in windows only? –  RootL Oct 22 '12 at 10:09
    
location and rewrite must be inside a server{} block. I don't see any of those in your configuration. Do you have any? You might need to add more of your configuration until we can see the cause of the error. –  Ladadadada Oct 23 '12 at 14:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.