【问题标题】:How to servers my homepage with and HTML file and all others paths/urls with a PHP file如何使用 PHP 文件为我的主页和 HTML 文件和所有其他路径/url 提供服务
【发布时间】:2016-04-12 02:35:46
【问题描述】:

我想要实现的是,如果有人访问我的主页/索引页面,我需要提供我的 index.html 文件。但是,如果它是另一个 URL/路径,则将请求传递给我的 index.php 文件(我正在使用 Symfony)。

我关注this example,但没有工作。它总是为我的 PHP 文件提供服务。

server 
{
    listen       80;
    server_name mysite.com;

    root   /path/to/my/web;
    index index.html index.php;

    location = /index.html 
    {
        try_files $uri /index.html?$args;
    }

    location / 
    {
        try_files $uri /index.php?$args;
    }

}

如果您能与我分享任何帮助或指导,我将不胜感激。

【问题讨论】:

    标签: nginx nginx-location


    【解决方案1】:

    这终于对我有用了:

    server 
    {
        listen       80;
        server_name mysite.com;
    
        root   /path/to/my/web;
        index index.html index.php;
    
        location = / 
        {
            try_files $uri /index.html?$args;
        }
    
        location / 
        {
            try_files $uri /index.php?$args;
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-23
      • 2013-06-11
      • 2017-05-08
      • 1970-01-01
      • 2015-09-07
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      相关资源
      最近更新 更多