[英]NGINX nice url configuration
在 NGINX 上,我試圖弄清楚如何在重定向到 php 文件后在地址欄中保留漂亮的 URL。 我已經在代碼中嘗試了下面提到的所有方法並且它工作正常但無論是否使用重定向或代理,我仍然在地址欄中看到www.mydomain.com/products.php 。 我需要讓地址看起來像www.mydomain.com/products 。 有什么想法嗎?
server {
server_name mydomain.com www.mydomain.com;
root /var/www/mydomain.com;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
location /products {
#rewrite ^/products$ /products.php last;
#try_files $uri $uri/ /products.php;
proxy_pass http://localhost/products.php;
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 ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
解決了,我把它復雜化了,最簡單的方法很好用。
location /products {
rewrite ^/products /products.php last;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.