将根请求定向到子URL和双斜杠

时间:2015-08-19 20:48:44

标签: nginx

所以,在我的应用程序中,我希望任何以/ ur结尾的根URL到/ pss

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
error_log  logs/error.log debug;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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

    server_name_in_redirect off;

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

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    # Enable Gzip
    gzip  on;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_min_length 1100;
    gzip_buffers     4 8k;
    gzip_proxied any;
    gzip_types
    # text/html is always compressed by HttpGzipModule
        text/css
        text/javascript
        text/xml
        text/plain
        text/x-component
        application/javascript
        application/json
        application/xml
        application/rss+xml
        font/truetype
        font/opentype
        application/vnd.ms-fontobject
        image/svg+xml;

    gzip_static on;

    gzip_proxied        expired no-cache no-store private auth;
    gzip_disable        "MSIE [1-6]\.";
    gzip_vary           on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;
        rewrite_log on;
        access_log  logs/host.access.log  main;

        index index.html index.htm;

        location ~ ^/pss/?(.*)$ {
          root /opt/tech-ui;
          rewrite ^/pss$ / break;
          rewrite ^/pss/(.*)$ /$1 break;
        }

        location / {
          root /opt/tech-ui;
        }

        location =/ {
            rewrite ^/(.*)$ /pss/$1 break;
            return 302;
        }

        error_page  404              /404.html;
        error_page  500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }


    # 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;
    #    }
    #}
   }

   daemon off;

所以,每当我在localhost中,我都会得到localhost // pss

我非常困惑,我已经用Google搜索了,我不知道接下来要做什么,我知道我在nginx中遗漏了一些基本内容。

1 个答案:

答案 0 :(得分:1)

您可以使用下面的重写规则:

location = / {
    rewrite ^ /pss&$args last;
}

location = / {
    return 301 http://localhost/pss;
}