nginx multiple locations for one rule regex

匆匆过客 提交于 2019-12-06 13:27:14

Try ...

location ~ (\.php|sitemap\.xml|api/api\.js)$ {
    ...
}

You shouldn't really be trying to force Nginx to send things to PHP. That's kind of 'the wrong way'. You should let Nginx see if the file exists and pass if it doesn't. It's understood that *.php needs to be processed by PHP so you pass .php.

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

location ~ \.php {
    fastcgi_pass unix:/tmp/php-fpm.socket;
}

location = /api/api.js {
    fastcgi_pass unix:/tmp/php-fpm.socket;
}

location = /sitemap.xml {
    fastcgi_pass unix:/tmp/php-fpm.socket;
}

Trying to maintain a regular expression for locations when you don't understand how Nginx location blocks work is going to be extremely painful in the long run.

http://wiki.nginx.org/HttpCoreModule#location

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!