繁体   English   中英

NGINX 不错 url 配置

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM