<div>Hi all,<br></div><div><br></div><div>What's the difference between below two conf?</div><div><br></div><div>Nginx can start normally with both conf, but rewrite only works fine with the first conf.</div><div><br></div>
<div><br></div><div>1.</div><div>server {<br>        listen 80; ## listen for ipv4<br>        listen [::]:80 default ipv6only=on; ## listen for ipv6<br>        server_name localhost;<br>        access_log /var/log/nginx/nginx.log;<br>         log_format access '$remote_addr - $remote_user [$time_local] "$request" '<br>
'$status $body_bytes_sent "$http_referer" '<br> '"$http_user_agent" $http_x_forwarded_for';<font color="#ff6666"><br>        location / {<br>                root /var/www/html;<br>
                index index.htm index.php index.html;<br><br>                </font><font color="#339999">rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;<br>                rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;<br>
                rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;<br>                rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;<br>
                rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;<br>                rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;<br>                rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last;<br>
                if (!-e $request_filename) {<br>                 return 404;<br>                }</font><font color="#ff6666"><br>        </font><font color="#ff6666">}</font><br>        location ~ \.php$ {<br>                fastcgi_pass unix:/tmp/php-cgi.sock;<br>                fastcgi_index index.php;<br>
                fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;<br>                include fastcgi_params;<br>        }<br>}<font color="#ff6666"><br></font><br></div><div><br></div><div>2.</div><div>server {<br>        listen 80; ## listen for ipv4<br>
        listen [::]:80 default ipv6only=on; ## listen for ipv6<br>        server_name localhost;<br>        access_log /var/log/nginx/nginx.log;<br>         log_format access '$remote_addr - $remote_user [$time_local] "$request" '<br>
'$status $body_bytes_sent "$http_referer" '<br> '"$http_user_agent" $http_x_forwarded_for';<br>        <font color="#cc0000">location / {<br>                root /var/www/html;<br>
                index index.htm index.php index.html;<br>        }</font><br>                <font color="#3333ff">rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;<br>                rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;<br>
                rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;<br>                rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;<br>
                rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;<br>                rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;<br>                rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last;<br>
                if (!-e $request_filename) {<br>                 return 404;<br>                }</font><br>        location ~ \.php$ {<br>                fastcgi_pass unix:/tmp/php-cgi.sock;<br>                fastcgi_index index.php;<br>                fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;<br>
                include fastcgi_params;<br>        }<br>}<br></div><div><font color="#ff6666"><br></font></div><div><font color="#ff6666"><br></font></div>