Articles of nginx

Nginx重写规则用下划线replace查询string问号

为了将整个网站镜像为静态HTML, 我想将urlhttp://example.com/script.php?t=12转换为http://example.com/script.php_t=12 。 注意? 在URL正在被转换为_ 。 这将允许nginx或apache从磁盘提供这些文件作为我们获得的原始HTML,并从wget保存 – 每个URL的一个文件 – 而不是一个PHP文件。 是否有可能通过Nginx的URL重写?

我怎样才能使nginx支持@ font-face格式并允许访问控制允许来源?

我已经将这些规则添加到mime.types : application/x-font-ttf ttf; font/opentype otf; application/vnd.ms-fontobject eot; font/x-woff woff; 现在,Content-Type头部被正确设置。 我现在唯一的问题是Firefox需要Access-Control-Allow-Origin。 我GOOGLE了这个答案,并将其添加到我的服务器指令: location ~* \.(eot|ttf|woff)$ { add_header Access-Control-Allow-Origin *; } 但现在我的字体根本没有被服务。 相反, error.log报告它试图在本地文件系统上打开它们。 2010/10/02 22:20:21 [error] 1641#0:* 15 open()“/usr/local/nginx/html/fonts/mgopenmodernabold-webfont.woff”失败(2:没有这样的文件或目录) ,客户端:69.164.216.142,服务器:static.arounds.org,请求:“HEAD /fonts/mgopenmodernabold-webfont.woff HTTP / 1.1”,主机:“static.arounds.org” 任何想法可以用语法closures? 我是否需要明确添加规则,说不要试图在本地打开它或什么? 编辑 :我认为问题是我现在服务2个不同的位置。 而不是我应该做的主正面的正则expression式检查然后喂给头。

在Nginx上允许404响应的交叉源请求(CORS)

我使用Nginx来使用这个问题中概述的技术来响应CORS请求提供静态文件。 但是,当文件不存在时,404响应不包含Access-Control-Allow-Origin: *头,浏览器也是如此。 如何发送Access-Control-Allow-Origin: *在404响应?

使用Nginx将非wwwredirect到www

尝试将https://example.comredirect到https://www.example.com时出现错误。 当我转到https://example.com时 ,它不会redirect并返回页面/ 200状态。 我不想要这个,我希望它redirect到https://www.example.com 。 当我访问http://example.com时 ,它会redirect到https://www.example.com 有人可以告诉我我要去哪里吗? 这是我的默认和default-sslconfiguration文件: default.conf server { listen 80; server_name example.com; return 301 https://www.example.com$request_uri; } 默认的ssl.conf upstream app_server_ssl { server unix:/tmp/unicorn.sock fail_timeout=0; } server { server_name example.com; return 301 https://www.example.com$request_uri } server { server_name www.example.com; listen 443; root /home/app/myproject/current/public; index index.html index.htm; error_log /srv/www/example.com/logs/error.log info; access_log /srv/www/example.com/logs/access.log combined; ssl […]

将通配符子域redirect到https(nginx)

我有一个通配符sslauthentication,我试图将所有非sslstream量redirect到ssl。 目前,我正在使用以下redirect的非子域名url工作正常。 server { listen 80; server_name mydomain.com; #Rewrite all nonssl requests to ssl. rewrite ^ https://$server_name$request_uri? permanent; } 当我为* .mydomain.com做同样的事情时,它在逻辑上redirect到 https://%2A.mydomain.com/ 你如何将所有子域名redirect到他们的https等价物?

有没有一种优雅的方法来一次阻止一群引用者?

为了防止引用垃圾邮件,我的nginx.conf包含这样一个部分: if ($http_referer ~* spamdomain1\.com) { return 444; } if ($http_referer ~* spamdomain2\.com) { return 444; } if ($http_referer ~* spamdomain3\.com) { return 444; } 这些规则告诉nginx只是closures连接,如果用户有这些推荐人之一设置。 有没有更优雅的方式来做到这一点? 我可以定义这些域的列表,然后说:“如果引用者在这个列表中,然后返回444”?

nginx代理传递redirect忽略端口

所以当我在nginx conf中指向一个node.js应用程序时,我正在设置一个虚拟path。 相关部分如下所示: location /app { rewrite /app/(.*) /$1 break; proxy_pass http://localhost:3000; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } 除了当我的node.js应用程序(一个快速应用程序)调用redirect时,效果很好。 作为一个例子,开发盒在端口8080上运行nginx,所以url到节点应用程序的根目录如下所示: HTTP://本地主机:8080 /应用程序 当我从节点调用redirect到'/ app'时,实际的redirect转到: HTTP://本地主机/应用

HAProxy和Ngnix在反向代理模式下的区别是什么?

HAProxy和Nginx在作为反向代理的能力方面有什么区别?

如何更改NGINX用户?

我有一个PHP脚本创build一个目录,并将图像输出到目录。 这在Apache下工作得很好,但是我们最近决定切换到NGINX来更多地使用我们有限的RAM。 我正在使用PHP mkdir()命令来创build目录: mkdir(dirname($path['image']['server']), 0755, true); 切换到NGINX后,我收到以下警告: Warning: mkdir(): Permission denied in … 我已经检查了父目录的所有权限,所以我确定我可能需要更改NGINX或PHP-FPM的“用户”,但我不知道该怎么做(我从来没有指定用户APACHE权限)。 我似乎无法find关于此的很多信息。 任何帮助将是伟大的! (注意:除了这个小小的挂断之外,切换到NGINX已经非常的无缝了,我第一次使用它,从字面上来说,花了大约10分钟就可以用NGINX启动和运行。摆脱困境。)

Nginx上的SSL握手协议非常慢

我使用Nginx作为4个Apache实例的代理。 我的问题是SSL协商需要很多时间(600毫秒)。 以此为例: http : //www.webpagetest.org/result/101020_8JXS/1/details/ 这是我的Nginx Conf: user www-data; worker_processes 4; events { worker_connections 2048; use epoll; } http { include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; sendfile on; keepalive_timeout 0; tcp_nodelay on; gzip on; gzip_proxied any; server_names_hash_bucket_size 128; } upstream abc { server 1.1.1.1 weight=1; server 1.1.1.2 weight=1; server 1.1.1.3 weight=1; } server { […]