如何在Nginx上设置SPDY协议?

13
我有一个Rails应用程序,想设置Google SPDY协议支持。但是,在安装了带有SPDY补丁的Nginx并在虚拟主机中启用spdy后,它不允许我重新启动nginx,而是抛出以下错误。
Restarting nginx: nginx: [emerg] invalid parameter "spdy" in /etc/nginx/sites-enabled/default:112
nginx: configuration file /etc/nginx/nginx.conf test failed

我已经编译了最新的nginx 1.3.13,并加入了spdy补丁,这里我将列出我的安装步骤。

wget http://nginx.org/download/nginx-1.3.13.tar.gz
tar xvfz nginx-1.3.13.tar.gz
cd nginx-1.3.13

# Fetch the SPDY patch and apply it
wget http://nginx.org/patches/spdy/patch.spdy.txt
patch -p1 < patch.spdy.txt

 ./configure \
 --sbin-path=/usr/local/sbin/nginx \
 --prefix=/etc/nginx \
 --conf-path=/etc/nginx/nginx.conf \
 --error-log-path=/var/log/nginx/error.log \
 --http-client-body-temp-path=/var/lib/nginx/body \
 --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
 --http-log-path=/var/log/nginx/access.log \
 --http-proxy-temp-path=/var/lib/nginx/proxy \
 --http-scgi-temp-path=/var/lib/nginx/scgi \
 --http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
 --lock-path=/var/lock/nginx.lock \
 --pid-path=/var/run/nginx.pid \
 --with-debug \
 --with-http_addition_module \
 --with-http_dav_module \
 --with-http_gzip_static_module \
 --with-http_realip_module \
 --with-http_stub_status_module \
 --with-http_ssl_module \
 --with-http_sub_module \
 --with-http_xslt_module \
 --with-http_spdy_module \
 --with-ipv6 \
 --with-sha1=/usr/include/openssl \
 --with-md5=/usr/include/openssl \
 --with-mail \
 --with-mail_ssl_module \

 # wget https://you.googlecode.com/files/ngx_cache_purge-1.6.tar.gz
 --add-module=/software/ngx_cache_purge-1.6 \

 #http://www.openssl.org/source/openssl-1.0.1e.tar.gz
 --with-openssl='/software/openssl-1.0.1e' 

 # Build and install nginx
 make && sudo make install

它能够成功编译且没有出现任何错误。 运行 nginx -V 命令会返回以下结果。

nginx version: nginx/1.3.13
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
TLS SNI support enabled
configure arguments: --sbin-path=/usr/local/sbin/nginx --prefix=/etc/nginx --conf-           path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --with-debug --with-http_addition_module --with-http_dav_module --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-http_xslt_module --with-http_spdy_module --with-ipv6 --with-sha1=/usr/include/openssl --with-md5=/usr/include/openssl --with-mail --with-mail_ssl_module --add-module=/software/ngx_cache_purge-1.6 --with-openssl=/software/openssl-1.0.1e

我的 /etc/nginx/site-enabled 配置有

server {
      listen 443 ssl spdy;

      ssl_certificate      server.crt;
      ssl_certificate_key  server.key;  

      ...
  }

在所有这些成功的安装中,nginx在site-enabled文件的服务器块中使用spdy参数时无法重新启动。有什么建议吗?我确定错过了一些东西,但是想不出来。

1
SPDY本身并不是一个很大的优势,但与TCP/IP调优相结合使用则会有更好的效果。https://coderwall.com/p/8igwqa - Anatoly
请按照这篇文章 http://www.liberiangeek.net/2014/10/install-latest-version-nginx-ubuntu-14-10/ 进行操作。 - AntonAL
1个回答

13

更新(2013年11月19日):修改了脚本以适用于nginx 1.4.3(无需spdy补丁)

https://gist.github.com/deepak-kumar/7541199#file-compile_nginx_1-4-3_with-spdy-sh

我编写了Shell脚本进行设置

https://gist.github.com/deepak-kumar/5069550#file-compile_nginx_with_spdy-sh

我已经找到了解决问题的方法。
在编译1.3.13之前,我已经在我的Ubuntu 12.04上安装了nginx软件包,这导致了问题的出现。$ sudo apt-get install nginx 为了解决这个问题,我确保/etc/init.d/nginx使用正确的二进制文件。
我在终端上执行了以下操作:
$ which nginx
$ /usr/local/sbin/nginx

我检查了现有的/etc/init.d/nginx脚本,发现它使用了错误的DAEMON路径,所以我将其更改为以下内容(可以正常工作)

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx # $which nginx

之前的值为(不起作用)

#PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#DAEMON=/usr/sbin/nginx

其余部分文件保持不变。因此,本质上我使用了正确版本的二进制文件。
更新:如果你们感兴趣,这篇博客也是一个非常好的参考点。 http://blog.bubbleideas.com/2012/08/How-to-set-up-SPDY-on-nginx-for-your-rails-app-and-test-it.html

可能更容易的方法是使用 "apt-get remove nginx" 命令来卸载 Nginx,但如果在生产系统上工作,则会烧毁你的桥梁。 - Julian
这个针对nginx 1.6.2的shell脚本有更新吗?该脚本似乎在Ubuntu 14.0.4上无法支持最新版本的nginx。 - Marvin Danig
1
@marvindanig 这应该会有所帮助。而且,您不再需要补丁,只需在编译时传递--with-http_spdy_module选项即可。http://blog.glaucocustodio.com/2014/11/24/adding-support-to-spdy-protocol-on-nginx-with-zero-downtime/ - ʞɹᴉʞ ǝʌɐp
感谢@DaveKirk,我已经掌握了这个问题并在这里写了一篇文章-> http://marvindanig.svbtle.com/how-to-set-up-ssl-with-spdy-and-nginx - Marvin Danig

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接