Articles of nginx

Nginxredirect所有子文件夹,但文件夹本身

我有一个Wordpress安装名称的奇怪冲突,我需要写一些Nginx规则来修复它。 我曾经在Wordpress页面/项目中列出我的软件项目,并链接到子页面/ projects / aprojectname , / projects / anothername等。 最近,我购买了一个自定义posttypes的主题组合项目。 它被称为项目 (注意缺less的 )。 在/项目 ,我访问所有项目职位的默认Wordpress列表。 然后,我可以使用/ project / aprojectname , / project / anothername等来访问post 到现在为止还挺好。 问题是我想使用新的/项目结构保留任何以前的链接到我/项目/东西。 此外,我想只保留/项目页面(不redirect)。 这是我想要完成的。 该URL /项目 只应该redirect到/项目 ,以便我可以显示一个WordPress的页面,而不是“丑陋的”Wordpress的职位列表。 因此,URL /项目不应该被处理。 它应该显示相应的Wordpress页面。 但是, / projects / something中的所有 URL 都应该redirect到/ project / something 这是我迄今为止的nginx规则。 location ~ ^/projects/(.*) { return 301 http://$server_name/project/$1; } […]

如何在nginx上设置子域名?

我已经在下面的path/home/git/gitlab/设置了我的unbuntu ubuntu 12.04 lts服务器上的GitLab 。 我正在使用nginx服务器。 这是我的gitlab状态 root@c27-76:/etc# sudo service gitlab status The GitLab Unicorn web server with pid 3187 is running. The GitLab Sidekiq job dispatcher with pid 3197 is running. GitLab and all its components are up and running. 我无法为gitlab设置子域。 我想要一个像gitlab.domain.com这样的域名。 这是我在/ etc / nginx / sites-avaliable上的gitlab文件 server { listen 80; ## listen […]

Nginx反向代理到另一个服务于静态文件的nginx服务器

我有一个Nginx服务器托pipe一个Web应用程序,直接访问时工作正常。 它的configuration如下 server { listen 8000 default_server; listen [::]:8000 default_server ipv6only=on; root /data/www/ ; server_name server1.com; location / { try_files $uri $uri/ =404; } location /app/ { } } 现在我必须从另一个Nginx服务器来服务这个应用程序所以我设置了如下的反向代理 server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /data/www/ ; server_name server2.com; location / { try_files $uri $uri/ =404; } location /app/ { […]

如何获得相当于Apache的别名“/ foo”/ path / to / foo在nginx中工作

我正在尝试在HHVM前面configurationnginx来提供一个API,其中有一个登陆页面列出了/中的可用版本,以及/ api / [version] /中实际安装的API版本。 到目前为止,我的nginxconfiguration如下: server { listen *:80; server_name api.domain.com; # Character Set charset utf-8; # Logs access_log /www/vhosts/api.domain.com/logs/access_log.nginx; error_log /www/vhosts/api.domain.com/logs/error_log.nginx; # Directory Indices index index.php; # Document Root root /www/vhosts/api.domain.com/public; # Location location /assets { try_files $uri $uri/ =404; } location /api/1.0 { root /www/vhosts/api.domain.com/api/1.0/public; rewrite ^/api/1.0(.*)$ /index.php$1; try_files $uri $uri/ /index.php?$query_string; […]

Nginx的file upload暂停/中间(上传只有258kb和停止) – 408请求超时

我已经安装了bitnami nginx栈(nginx,php-fpm,mysql)来运行多个drupal 7和node.js站点,但是现在只有一个D7站点被安装了。 file upload在localhost中完美工作。 但是,只要我上传到Linode vps与bitnami nginx堆栈,它开始显示上传问题。 对于较小的文件(〜60kb)上传工作正常。 但是对于更大的文件,上传暂停。 less数情况下:563KB文件 – 上传停止在46%3.5MB文件 – 停止在〜7% 访问日志看起来像这样的POST(给出408): xxxx – – [07/Sep/2014:20:15:24 +0530] "POST /node/add/profile HTTP/1.1" 408 0 "http://mysite[dot]com/node/add/profile" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36" 尝试了一切,我可以在nginx.conf文件,但没有什么帮助。 user daemon daemon; worker_processes 1; error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid […]

如何在后台升级期间挂起Nginx请求

我希望Nginx暂时(暂停)短暂的HTTP请求,而我升级或重新启动后端服务,执行数据库迁移或其他pipe理任务,而不会导致最终用户的错误。 基本上我想要做以下一系列的操作: 告诉Nginx停止将请求转发到我的后端,而不是将它们保存在其asynchronous队列中; 等到所有待处理的后端请求完成后再通知; 升级,重启或以其他方式对空闲的后端服务进行操作; 使用其私有地址快速validation后端服务是否正常运行; 打开Nginx的防洪门,让所有未决的请求通过。 理想情况下,这可以让我执行需要对整个后端服务器进行独占访问的pipe理任务,例如重新启动,升级或迁移,而不会导致最终用户比延迟更严重,希望不到一分钟。 我已经find了这个解决scheme ,但是这不是解决问题的第二点。而且,它需要将Lua解释器编译到Nginx中,这可能意味着任何内存泄漏和安全问题。 有没有任何configuration技巧或Nginx的模块专门针对这个问题? 可以用Nginx的库存来完成,也许可以通过testing控制文件的存在吗? 其他pipe理员如何解决这个问题呢? (我知道uWSGI应用程序服务器的全function和有点庞大,在其他数百个应用服务器中有这个function,但是我宁愿避免在Nginx和后端之间引入另一个元素。)

(111:连接被拒绝),同时连接到上游 – Opsworks Rails 4

我在OpsWorks(Ubuntu 14.04,nginx和unicorn)中部署了一个rails 4应用程序,当我打开主页的时候,我得到一个502错误的网关错误。 在nginx / error.log中我可以看到这个错误: 2015/01/25 06:19:42 [error] 3652#0: *1 connect() to unix:/srv/www/app/shared/sockets/unicorn.sock failed (111: Connection refused) while connecting to upstream, client: IP, server: app$ 在这里你可以看到我的nginx.conf的更多信息: user www-data; worker_processes 10; error_log /var/log/nginx/error.log; pid /run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout […]

gzip_ratio不打印在nginx日志中

我正在configurationnginx access_log以JSON格式输出,以便与其他工具一起使用。 我想要的数据包括有关压缩的信息。 我有gzip,但我得到的唯一的gzip_ratio是- 。 为了确认,embedded的$gzip_ratio是$gzip_ratio 。 http://nginx.org/en/docs/http/ngx_http_gzip_module.html 这里是我的log_format的定义: log_format main_json '{"time": "$time_iso8601", ' '"remote_addr": "$remote_addr", ' '"body_bytes_sent": "$body_bytes_sent", ' '"gzip_ratio": "$gzip_ratio", ' '"status": "$status", ' '"request": "$request_time", ' '"request_method": "$request_method", ' '"http_referrer": "$http_referer", ' '"http_user_agent": "$http_user_agent", ' '"http_x_forwarded_for": "$http_x_forwarded_for", ' '"request_time": "$request_time", ' '"upstream_response_time": "$upstream_response_time"}'; 这里是nginx.conf中的gzip设置: gzip on; gzip_proxied any; gzip_types text/plain text/xml text/css […]

如何在使用CloudFlare + Nginx + Apache时logging客户端的真实IP地址

我一直试图解决这个问题,我希望有人能帮助我。 我有Nginx站在Apache面前的反向代理。 我只能在没有CloudFlare的情况下使用Nginx + Apache来使用mod_rpaf模块来logging客户端的真实IP。 然后我决定添加CloudFlare到我的服务器。 现在, CloudFlare IP正在显示,而不是客户端的IP。 我安装了Nginx的 RealIP Module ,我尝试了各种configuration,但没有解决问题。 然后,我安装了mod_cloudflare ,它应该按照CloudFlare上的描述将真实客户端的IPlogging到Apache ,但是这也没有解决问题。 首先,Nginx + Apache的工作configuration如下: Nginxconfiguration: proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; real_ip_header X-Client-IP; mod_rpafconfiguration: LoadModule rpaf_module /usr/local/apache/modules/mod_rpaf-2.0.so <IfModule mod_rpaf-2.0.c> RPAFenable On RPAFproxy_ips 127.0.0.1 #Proxy IPs RPAFsethostname On RPAFheader X-Client-IP </IfModule> 到目前为止,客户的真实IP地址正确显示。 如果有人正在寻找logging真实客户端的IP地址,可以使用上述configuration。 其次,使用CloudFlare与Nginx + […]

使用基本authentication保护Nginx上的Piwik,但允许访问piwik.js

我在我的服务器上运行了nginx,最近用这个configuration安装了Piwik: server { listen 443 ssl spdy; server_name analytics.example.org; root /srv/www/analytics.example.org; index index.php; ssl_certificate ssl-certificates/wildcard.example.org.crt; ssl_certificate_key ssl-certificates/wildcard.example.org.key; access_log /var/log/nginx/analytics.example.org_access.log; error_log /var/log/nginx/analytics.example.org_error.log; auth_basic "HTTP Basic Authentication"; auth_basic_user_file htpasswd/example; satisfy any; include example_ip; deny all; location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires max; } location = /robots.txt { return 200 "User-agent: *\nDisallow: /\n"; } location / { try_files $uri […]