Articles of nginx

如何使nginx在空文件上返回404?

我正在查看是否有可能根据文件大小进行条件重写。 就像是: if (!-s $request_filename) { return 404; } 我假设-s返回true,如果文件存在,是非空的。 我需要这个,因为我有一个脚本,dynamic创build文件,这些文件不应该服务,直到我写完了他们。 因此,如果文件是空的,他们应该404。

Nginx错误页面没有加载静态内容

运行Nginx 1.4.1我有下面的configuration来显示一个自定义的错误页面,以防我的后端弄乱了。 该页面显示,但自定义字体和图像不加载。 我的自定义错误页面(50x.html)位于/ usr / share / nginx / html /中。 子文件夹中的静态内容img&fonts。 从我的浏览器,我可以看到,静态内容url附加到我目前的url,使其不可用。 例如,如果我浏览www.domain.com/user/account,Nginx将尝试从服务器加载内容: URL /user/account/img/logo.png /user/account/img/main.jpg /user/account/img/footer.png /user/account/fonts/miso-regular-webfont.ttf 而不是从sr / share / nginx / html / img / 这里是configuration部分: error_page 324 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; allow all; internal; } 感谢您的灯光。 编辑1: 谢谢阿列克谢,path现在纠正,但图像仍然不显示。 在最初的后端故障中,Nginx尝试从Apache获取图像,而Nginx应该服务整个维护页面,而不依赖于后端。 为什么这种行为? 当一个backen生病时,我不能依靠它,即使是一个维护页面。 谢谢。

为什么我的浏览器不会一次加载所有的图像资源?

我正在尝试优化网页的加载时间。 目前,主要的http请求可以在一秒钟内完成,但是,图像的随机加载似乎是“级联”的: http://picpaste.novarata.net/pics/320bd387b4988729ad2dbb10f69a7857.png 我正在使用nginx来服务我的静态文件,3名工人。 有没有可能连接被积压? 我会假设所有这些图像将被同时加载。 文件通过HTTPS提供,Keepalive设置为65秒。 编辑:火狐确实似乎尝试一次加载它们,但是,连接时间逐渐增加到2秒以上: http://picpaste.novarata.net/pics/32c28414501d165df3e04b01e3ac3084.png

独angular兽显示机架错误未初始化的常量Rack :: Lint :: REQUEST_METHOD

我试图在Ubuntu 14.04上安装Unicorn + Nginx。 每当该网站被访问(通过本地主机:8080或通过Nginx)它只是返回一个空白的500错误。 错误日志给了我以下内容: NameError: uninitialized constant Rack::Lint::REQUEST_METHOD /var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/lint.rb:298:in `check_env' /var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/lint.rb:43:in `_call' /var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/lint.rb:37:in `call' /var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/showexceptions.rb:24:in `call' /var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/commonlogger.rb:33:in `call' /var/lib/gems/1.9.1/gems/sinatra-1.4.6/lib/sinatra/base.rb:218:in `call' /var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/chunked.rb:54:in `call' /var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/content_length.rb:15:in `call' /usr/lib/ruby/vendor_ruby/unicorn/http_server.rb:580:in `process_client' /usr/lib/ruby/vendor_ruby/unicorn/http_server.rb:660:in `worker_loop' /usr/lib/ruby/vendor_ruby/unicorn/http_server.rb:527:in `spawn_missing_workers' /usr/lib/ruby/vendor_ruby/unicorn/http_server.rb:153:in `start' /usr/bin/unicorn:126:in `<main>' E, [2015-04-11T11:20:00.945818 #25817] ERROR — : app error: uninitialized constant Rack::Request::SCRIPT_NAME (NameError) E, [2015-04-11T11:20:00.945882 #25817] ERROR — : /var/lib/gems/1.9.1/gems/rack-1.6.0/lib/rack/request.rb:21:in […]

Nginx的www到非www,转发到http,并转发到https在特定的位置

在我的nginxconfiguration中,我打算达到以下目的: 转发www到非www 将https转发给http 只使用模式“安全”的uri上的https 下面的代码达到目标,除了在第3点 ,Chrome显示空白页面,错误“此网页有一个redirect循环”。 任何人都可以告诉适当的configuration,和/或任何更好的代码? #redirect www to non-www server { listen 80; server_name www.example.org; return 301 http://example.org$request_uri; } #redirect https to http, for both www and non-www #but process https for uri with pattern 'secure' server { ssl_certificate /home/mydomain/ssl.cert; ssl_certificate_key /home/mydomain/ssl.key; listen 443 ssl; server_name www.example.org example.org; root /home/mydomain/public_html/mydomain/public; index index.php; access_log […]

Nginx位置匹配导致404

我试图为某些文件types添加行为,但是因为我的内容不在同一个文件夹中,所以我遇到了一个位置匹配导致Nginx在错误的文件夹中查找内容的问题。 接下来,对/wp-content/themes/ryu/fonts/ClearSans-Regular.woff的请求使得nginx在/opt/wordpress/wp-content/themes/ryu/fonts/ClearSans-Regular.woff查找文件而如果我注释的location ~* \.(ogg|ogv|svg|svgz|eot …部分,Nginx在正确的位置寻找内容。 任何线索我怎么能做到这一点? server { listen *:80; root /opt/wordpress; location ~* \.(eot|ttf|woff)$ { add_header Access-Control-Allow-Origin *; } location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } location /wp-content/ { alias /opt/wp-content/; try_files $uri =404; } location / { alias /opt/public/; expires 1d; index index.html; try_files $uri @wpsupercache; } }

nginx访问控制源标题已configuration但不起作用

我正在得到一个 XMLHttpRequest cannot load http://website2.com/ads/dev_642e92efb79421734881b53e1e1b18b6/5534f8e14d514_1.html. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://website1.com' is therefore not allowed access. Website2是使用nginxconfiguration的: server { listen 80; server_name website2.com; root /var/www/website2; index index.php index.html index.htm; #try_files $uri $uri/ /index.php?$args; client_max_body_size 20M; location /ads { add_header 'Access-Control-Max-Age' 1728000; add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, […]

在Docker容器中运行多个网站,如何实现?

我正在运行两个docker集装箱,使用下面的dockercomposer php脚本: db: image: cofoundry/mysql environment: – MYSQL_USER=wordpress – MYSQL_PASS=wordpress – MYSQL_DB=wordpress ports: – "3306:3306" privileged: true web: image: cofoundry/nginx-phpfpm volumes: – ../bedrock:/app environment: – DOCROOT=/app/web links: – db ports: – "80:80" privileged: true 但是我找不到任何地方,我怎么能为不同的网站运行多个nginx-phpfpm web和mysql容器,比如web_1 – db_1,web_2 – db_2等。 另外我更改了/ etc / hosts文件以使用boot2docker ip列出所需的所有域,但是如何为它们运行容器? 我不能在相同的端口80和3306上运行容器。 请指教,谢谢!

为什么这个nginx重写规则添加了尾部的斜线?

我对位置/有以下重写规则,并强制执行尾部斜线! location / { rewrite ^(\/.*) https://example.com/ar$1 permanent; } 每次,我蜷缩mydomain.com,我得到了以下回应: HTTP/1.1 301 Moved Permanently Content-Type: text/html Connection: keep-alive Location: https://example.com/ar/ 我不想在redirect的URL末尾input斜线!

两个不同的目录与Nginx

我在我的服务器上有两个目录 ,其中有其他目录的目录1 ,以及具有单个文件 index.php的directory2 。 我想通过http:// server /var/www/directory2/index.php )访问我的index.php ,并且能够使用http:// server / test ( var/www/directory1/test )。 我尝试过这种configuration,但我无法访问index.php文件: server { server_name server; index index.php index.html index.htm; access_log /var/log/nginx/server.access.log; error_log /var/log/nginx/server.error.log; location / { root /var/www/directory1; } location ~ ^/index.php$ { root /var/www/directory2; try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri =404; fastcgi_index index.php; […]