NGINX中url地址内的变量用户名

NGINX中url地址内的变量用户名,nginx,Nginx,我仍然在努力使mystaticusername成为变量用户名。我的意思是当我有特定的用户名/站名/后端在nginx上正常工作时。但是我如何为更多的用户进行配置呢?意味着使用mystaticusername进行一些重定向,每个用户名都知道如何登录到后端 如何更改我的nginx配置 server { server_name example.com www.example.com; listen 80 default_server; listen [::]:80 defaul

我仍然在努力使mystaticusername成为变量用户名。我的意思是当我有特定的用户名/站名/后端在nginx上正常工作时。但是我如何为更多的用户进行配置呢?意味着使用mystaticusername进行一些重定向,每个用户名都知道如何登录到后端

如何更改我的nginx配置

server {
    server_name example.com www.example.com;

    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/www;
    charset utf-8;

    index index.html index.php /index.php;

    location = / {
            rewrite ^ /index.php;
    }
    location / {
            rewrite ^([^\.]*)$ /$1.php;
            rewrite ^/([A-Za-z0-9_]+)$ /admin/index.php?q=$uri&$args;
    }
    location ~ \.php$ {
            try_files $uri =404;
            include fastcgi_params;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }
    location /mystaticusername {
            try_files $uri/ /admin/index.php?q=$uri&$args;
    }
    location = /mystaticusername/options {
            try_files $uri $uri/ /admin/index.php?hotelname=$1&do=options;
    }
}

没有给出太多的上下文,所以我只是猜测。。。但看起来您可以将位置指令压缩为3条语句

这将默认为index.php,但是在example.com/mystaticusername的情况下,if将尝试该url,并且由于它不存在(猜测),它将提供/admin/index.php?q=$uri&$args。这也将允许像exmaple.com/about这样的URL解析。只需确保不允许用户创建“about”用户名

    location / {
            try_files $uri $uri/ /admin/index.php?q=$uri&$args;
    }
不确定您的目标是什么,但这会让您example.com/mystaticusername/options尝试service up/admin/index.php?hotelname=$1&do=options

    location ~* ^/[a-zA-Z0-9]*/options$ {
            try_files $uri /admin/index.php?hotelname=$1&do=options;
    }
让php保持原样

    location ~ \.php$ {
            try_files $uri =404;
            include fastcgi_params;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

你能解释一下你想要什么,你想要什么url,它们应该指向哪里吗?嘿@alexeyten现在当我写mystaticusername时,我的realusername来自数据库,一切都像我想要的,所以当我的url地址像www.example.com/makromat/options时,我的url重写工作正常,但当我更改用户名时,重定向不起作用。