如何location在Nginx中设置一个响应任何不符合列出位置的条件?
我试过了:
location !~/(dir1|file2\.php) {
rewrite ^/(.*) http://example.com/$1 permanent;
}
Run Code Online (Sandbox Code Playgroud)
但它不会触发重定向.它只使用服务器配置的其余部分中的规则处理请求的URI.
我正在尝试使用Nginx设置基本的HTTP身份验证,这是多层次的.我想为整个网站提供一个用户名和密码,除了某个子目录(URL),以及该子目录的单独用户名和密码.如果有人导航到该子目录,我希望它们仅被提示输入特定于子目录的凭据,而不是网站根目录的凭据.
我该如何设置?
我正在编写一个Dockerfile来设置我自定义的WordPress环境.我从ubuntu:latest开始,想通过将ENV变量设置为当前Ubuntu版本的代号来动态添加一些存储库.我怎么能这样做,还是有更好的方法来实现这一目标?
我遇到问题,try_files似乎没有将不存在的文件的请求传递给最后指定的值,在我的例子中是index.php.我正在使用Wordpress和我使用的XML Sitemap生成器插件创建虚拟XML文件和由Wordpress处理的虚拟robots.txt.不幸的是,try_files似乎没有将这些文件的请求传递给Wordpress.
这是我的服务器配置:
server {
## Web domain
server_name christiaanconover.com;
## Site root
root /var/www/christiaanconover.com;
## Index
index index.php index.htm;
## Common Wordpress configuration
include wp.conf;
## Include PHP configuration
include php.conf;
## Gzip Compression
include gzip.conf;
## Include W3TC configuration
include /var/www/w3tc/christiaanconover.com;
}
Run Code Online (Sandbox Code Playgroud)
我在这台服务器上运行多个单独的Wordpress站点,所以为了节省时间,我创建了一个文件wp.conf,其中包含Wordpress的所有常用配置元素.这是wp.conf的内容:
location / {
## Prevent PHP files from being served as static assets, and fall back to index.php if file does not exist
try_files $uri $uri/ /index.php?$args;
## If a file exists, serve it directly …Run Code Online (Sandbox Code Playgroud) nginx ×3
.htpasswd ×1
docker ×1
php ×1
regex ×1
robots.txt ×1
sitemap.xml ×1
ubuntu ×1
webserver ×1
wordpress ×1