首页 > 解决方案 > nginx 作为 PHP 服务入口点

问题描述

问题

这里的主要问题 - 如何在具有单独配置位置的 URL 中提供包含/vendor/前缀的静态资产?nginx

期望的行为是 -nginx作为应用证书的根入口点SSL,然后它为静态资产提供服务,所有其他请求都由php解释器处理。

标签: phpnginx

解决方案


你可以通过一个简单的配置来实现你想要的,比如:

location / {
    # This is cool because no PHP is touched for static content.
    # include the "?$args" part so non-default permalinks doesn't break when using query string
    try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php-fpm/example.com.sock;
}

但如果你想获得终极性能,请参阅这篇关于try_files缺点以及如何在没有它的情况下配置 NGINX 的文章。


推荐阅读