<div>Hi all,<br></div><div><br></div><div>What&#39;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  &#39;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#39;<br>
              &#39;$status $body_bytes_sent &quot;$http_referer&quot; &#39;<br>              &#39;&quot;$http_user_agent&quot; $http_x_forwarded_for&#39;;<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&amp;topic=$2 last;<br>                rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&amp;aid=$2&amp;page=$3 last;<br>
                rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&amp;fid=$2&amp;page=$3 last;<br>                rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&amp;tid=$2&amp;extra=page%3D$4&amp;page=$3 last;<br>
                rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&amp;fid=$2&amp;page=$3 last;<br>                rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&amp;$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  &#39;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#39;<br>
              &#39;$status $body_bytes_sent &quot;$http_referer&quot; &#39;<br>              &#39;&quot;$http_user_agent&quot; $http_x_forwarded_for&#39;;<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&amp;topic=$2 last;<br>                rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&amp;aid=$2&amp;page=$3 last;<br>
                rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&amp;fid=$2&amp;page=$3 last;<br>                rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&amp;tid=$2&amp;extra=page%3D$4&amp;page=$3 last;<br>
                rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&amp;fid=$2&amp;page=$3 last;<br>                rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&amp;$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>