我仍然在努力制作mystaticusername变量用户名。我的意思是当我有特定的用户名/ statisusername /后端在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;
}
}
答案 0 :(得分:1)
给出的上下文不多,所以我只是猜测...但看起来你可以将你的位置指令压缩为3个语句。
这将默认为index.php,但在example.com/mystaticusername的情况下如果尝试该url并且因为它不存在(猜测)它会提供/admin/index.php?q=$uri& ;的$ args。这也可以让exmaple.com/about等网址解析。只需确保不允许用户创建“约”的用户名
location / {
try_files $uri $uri/ /admin/index.php?q=$uri&$args;
}
不确定您的目标是什么,但这会让您获得example.com/mystaticusername/options尝试提供/admin/index.php?hotelname=$1&do=options
location ~* ^/[a-zA-Z0-9]*/options$ {
try_files $uri /admin/index.php?hotelname=$1&do=options;
}
保持php as-is
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}