【发布时间】:2020-04-09 03:33:23
【问题描述】:
我正在使用苗条的 nginx。该网站是活的,流浪的家园。我的网址的一个例子是
myurl.com/?page=admins
我想让它看起来像这样
myurl.com/page/admins
myurl.com/page/orders
只是想删除 ?并将 = 替换为 /
我已经尝试过这个和许多其他的东西,但现在暂时没有解决方案(我对此完全陌生,所以我有点迷茫)
到目前为止我的 etc/nginx/sites-available/myurl.com 文件:
server {
listen 80;
listen 443 ssl http2;
server_name .myurl.com;
root "/home/vagrant/code/admin";
index index.html index.htm index.php api.php;
charset utf-8;
location / {
try_files $uri $uri/ /api.php$is_args$args;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/myurl.com-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/myurl.com.crt;
ssl_certificate_key /etc/nginx/ssl/myurl.com.key;
}
server {
rewrite ^/page/(.*)$ /?page=$1 last;
location / {
proxy_pass https://myurl.com;
}
}
最后一段代码是我目前的尝试(罗伯特建议) 非常感谢您的帮助,因为我已经在这个问题上停留了几个小时,并且研究了几乎所有可用的资源!
【问题讨论】:
-
你在使用 Silm PHP 框架吗?如果是这样,您可以参考 Slim 用户指南的Nginx configuration 部分。
标签: nginx url-rewriting vagrant slim