小编Chr*_*aan的帖子

Nginx位置"不等于"正则表达式

如何location在Nginx中设置一个响应任何不符合列出位置的条件?

我试过了:

location !~/(dir1|file2\.php) {
   rewrite ^/(.*) http://example.com/$1 permanent;
}
Run Code Online (Sandbox Code Playgroud)

但它不会触发重定向.它只使用服务器配置的其余部分中的规则处理请求的URI.

regex webserver nginx

45
推荐指数
2
解决办法
9万
查看次数

Nginx密码保护root,并为子目录分隔密码

我正在尝试使用Nginx设置基本的HTTP身份验证,这是多层次的.我想为整个网站提供一个用户名和密码,除了某个子目录(URL),以及该子目录的单独用户名和密码.如果有人导航到该子目录,我希望它们仅被提示输入特定于子目录的凭据,而不是网站根目录的凭据.

我该如何设置?

nginx .htpasswd

4
推荐指数
1
解决办法
9760
查看次数

Docker:使用RUN命令设置ENV变量的值?

我正在编写一个Dockerfile来设置我自定义的WordPress环境.我从ubuntu:latest开始,想通过将ENV变量设置为当前Ubuntu版本的代号来动态添加一些存储库.我怎么能这样做,还是有更好的方法来实现这一目标?

ubuntu docker

4
推荐指数
1
解决办法
1259
查看次数

Nginx try_files不会触发index.php的响应

我遇到问题,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)

php wordpress robots.txt nginx sitemap.xml

1
推荐指数
1
解决办法
6032
查看次数