Heim  >  Artikel  >  php教程  >  Nginx1.2.0升级笔记

Nginx1.2.0升级笔记

WBOY
WBOYOriginal
2016-06-06 20:07:231064Durchsuche

昨天闲的蛋疼吧Nginx升级到了1.2.0,之前用的是1.0.14 1.0.14到1.2.0是一个大版本升级,配置文件有较大变化 写文章记录下碰到的问题以及解决办法 日志格式的定义不能放在每个server里了,必须写在http里 因此直接运行lnmp的升级脚本最后会报错,运行下面的se

昨天闲的蛋疼吧Nginx升级到了1.2.0,之前用的是1.0.14

1.0.14到1.2.0是一个大版本升级,配置文件有较大变化

写文章记录下碰到的问题以及解决办法

日志格式的定义不能放在每个server里了,必须写在http里

因此直接运行lnmp的升级脚本最后会报错,运行下面的sed脚本可以搞定

sed -i '/log_format.*/d;/.*http_user_agent.*/d;/\$status.*/d' /usr/local/nginx/conf/vhost/*.conf
sed -i 's/access_log  \/home\/wwwlogs\/\(.*\)\.log  .*/access_log  \/home\/wwwlogs\/\1\.log  nginx_log/' /usr/local/nginx/conf/vhost/*.conf
sed -i "\$i\log_format  nginx_log  '\$remote_addr - \$remote_user [\$time_local] \"\$request\" '" /usr/local/nginx/conf/nginx.conf 
sed -i "\$i\'\$status \$body_bytes_sent \"\$http_referer\" '" /usr/local/nginx/conf/nginx.conf
sed -i "\$i\'\"\$http_user_agent\" \$http_x_forwarded_for';" /usr/local/nginx/conf/nginx.conf

脚本是删除每个vhost里的日志格式定义,并且把日志格式名改为nginx_log,然后在http里定义一个nginx_log日志格式

运行完上面的命令,你可以重新载入一次nginx就ok了

但是我自己的升级完还出现了一个问题,博客一直显示welcome to nginx

指定路径访问就显示404或者no output

开始怀疑是未指定默认index文件,但是我所有配置都正确的

后来网上看到是1.1后的新功能try_files造成的,因为WP使用了rewrite

需要在php的请求后面加入一个配置,把404的请求转给php处理,配置如下

location ~ .*\.(php|php5)?$
true{
truetruetruetry_files $uri =404;
truetruetruefastcgi_pass  unix:/tmp/php-cgi.sock;
truetruetruefastcgi_index index.php;
truetruetrueinclude fcgi.conf;
true}

重新载入nginx就ok

不过也不是所有的都需要这样,在我vps上共有6个WP,但唯独我自己的博客需要加入这一行,其他不加入也完全正常

其实对于我来说没必要新版本,也没用到什么新功能,所以没事别瞎升级,不然会出现一些稀奇古怪的事情

昨天闲的蛋疼吧Nginx升级到了1.2.0,之前用的是1.0.14

1.0.14到1.2.0是一个大版本升级,配置文件有较大变化

写文章记录下碰到的问题以及解决办法

日志格式的定义不能放在每个server里了,必须写在http里

因此直接运行lnmp的升级脚本最后会报错,运行下面的sed脚本可以搞定

sed -i '/log_format.*/d;/.*http_user_agent.*/d;/\$status.*/d' /usr/local/nginx/conf/vhost/*.conf
sed -i 's/access_log  \/home\/wwwlogs\/\(.*\)\.log  .*/access_log  \/home\/wwwlogs\/\1\.log  nginx_log/' /usr/local/nginx/conf/vhost/*.conf
sed -i "\$i\log_format  nginx_log  '\$remote_addr - \$remote_user [\$time_local] \"\$request\" '" /usr/local/nginx/conf/nginx.conf 
sed -i "\$i\'\$status \$body_bytes_sent \"\$http_referer\" '" /usr/local/nginx/conf/nginx.conf
sed -i "\$i\'\"\$http_user_agent\" \$http_x_forwarded_for';" /usr/local/nginx/conf/nginx.conf

脚本是删除每个vhost里的日志格式定义,并且把日志格式名改为nginx_log,然后在http里定义一个nginx_log日志格式

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn