Nginx关闭版本号显示/隐藏nginx版本号
出于安全考虑,有时候会要求隐藏nginx的版本号编辑nginx.conf在http段加上server_tokens off;....省略部分....
http
{
include mime.types;
default_typeapplication/octet-stream;
....省略部分....
gzip on;
gzip_min_length1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zonecrawler$binary_remote_addr10m;
server_tokens off;
....省略部分....
server
{
....省略部分....重启或reload nginx就行了
在报404或curl -I时就不会出现版本号了 我用的是Lnmp0.9,nginx1.2.4,请教军哥,我按照上述操作然后重启lnmp后怎么会出现下面的信息?
=================================================================
Stoping LNMP...
Nginx program is stop
Shutting down php_fpm . done
PHP-FPM program is stop
Shutting down MySQL. SUCCESS!
MySQL program is stop
Starting LNMP...
nginx: unknown directive "user" in /usr/local/nginx/conf/nginx.conf:1
Nginx start successfully!
Starting php_fpmdone
PHP-FPM start successfully!
Starting MySQL. SUCCESS!
MySQL start successfully!
============================================
中间有错误信息,然后网站也无法打开了。这是什么原因?
回复 2# 的帖子
/usr/local/nginx/conf/nginx.conf里第一行有错误 我贴出我的nginx.conf,请军哥帮忙看一下:
=====================================================
userwww www;
worker_processes 8;
error_log/home/wwwlogs/nginx_error.logcrit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_typeapplication/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zonecrawler$binary_remote_addr10m;
server_tokens off;
以下内容略……
===========================================================
第一行的问题出在哪里呢?我只加了“ server_tokens off; ”这一行,别的什么都没有改变。
回复 4# 的帖子
我感觉应该是你用的编辑器的问题,你用什么编辑的? 感谢军哥提醒,就是编辑器的问题,我用的是EmEditor编辑器,编辑nginx.conf文件后默认保存为UTF-8(有签名)格式,这样就出错,重新保存为UTF-8(无签名)格式,就OK了。:lol:victory: 编辑器推荐用editplus 或者直接 vi修改也不会出错 要是能伪装掉nginx这个名字就更加好了,军哥,求教程回复 8# 的帖子
https://bbs.vpser.net/thread-10421-1-1.html
页:
[1]