nginx 配置伪静态,方便seo

如:http://localhost/newsDetails/40/2029.html    实际访问的是  http://localhost/newsDetails.html
核心: rewrite ^(.*)newsDetails/(\d+)$ $1lottery-info.html;
            rewrite ^(.*)newsDetails/(\d+)/(\d+).html$ $1newsDetails.html;


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#rewrite_log on;
#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            rewrite_log on;
            #root  html;
            # 新版PC地址
            root   E:\cpyzjpc;
            # H5地址
            #root  E:\H5;
            # 彩民之家
            #root  E:\CMZJ-NEW\CMZJ;
            index  index.html index.htm;
            #rewrite ^(.*)/news-details/([0-9]+)\.html$ $1/news-details.html?id=$2;
            #rewrite ^(.*)news-details-([0-9]+)\.html$ $1news-details.html?id=$2;

            # ^和$字符分别代表了匹配输入字符串的开始和结束
            # ()中的匹配到的内容会被按顺序分配到变量$1 $2 $3中
            # .*匹配任意字符串,且长度从0个到多个,故$1值为/
            # [0-9]+匹配字符0-9,长度1个到多个,故$2和$3分别是123和456

            rewrite ^(.*)newsDetails/(\d+)$ $1lottery-info.html?id=$2;
            rewrite ^(.*)newsDetails/(\d+)/(\d+).html$ $1newsDetails.html?id=$2&infotype=$2;
        }

        location /req {
            add_header 'Access-Control-Allow-Origin' '*';            
            # proxy_pass http://192.168.10.139:8080/;
            #proxy_pass http://192.168.10.152:8080/;
            #proxy_pass http://api.cpyzj.com/;
            #proxy_pass http://192.168.10.101/;
            # 测试接口地址
            proxy_pass http://test.api.cpyzj.com:8082/;
            # proxy_pass http://api.cpyzj.com/;
            #proxy_pass http://192.168.1.42:8081/;
            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;
        }

        location /reqs {
            add_header 'Access-Control-Allow-Origin' '*';            
            # proxy_pass http://192.168.10.139:8080/;
            #proxy_pass http://192.168.10.152:8080/;
            #proxy_pass http://api.cpyzj.com/;
            #proxy_pass http://192.168.10.101/;
            # 测试接口地址
            #proxy_pass http://test.api.cpyzj.com:8082/;
            proxy_pass http://test.api.cpyzj.com:8087/;
            # proxy_pass http://api.cpyzj.com/;
            #proxy_pass http://192.168.1.42:8081/;
            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;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 

你可能感兴趣的:(nginx)