我不知道我的nginx安装发生了什么事。 突然,所有的页面请求都被redirect到403页面。
昨天我试图添加一个用户代理来阻止,从这一点重新启动服务一切都被发送到403.我退出了这一变化,重新启动nginx ,一切仍然被导向到403页面。 即使我删除$http_user_agent和$http_referer if语句,一切仍然发送到403。
我甚至还从备份恢复整个nginx文件夹,我所有的页面请求继续被定向到403页面….
不知道如何解决这个问题,conf文件回来干净。 有请求进来时,我可以为nginx做些什么?
[root@soupcan nginx]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
这里是网站conf:
server { listen 80; server_name localhost; #charset koi8-r; access_log /var/log/nginx/website1/access.log main; error_log /var/log/nginx/website1/error.log; root /srv/www/website1; ## Block http user agent - morpheus fucking scanner ## if ($http_user_agent ~* "morfeus fucking scanner|ZmEu|Morfeus strikes again.|OpenWebSpider v0.1.4 (http://www.openwebspider.org/)") { return 403; } if ($http_referer ~* (semalt.com|WeSEE)) { return 403; } ## Only allow GET and HEAD request methods. By default Nginx blocks ## all requests type other then GET and HEAD for static content. if ($request_method !~ ^(GET|HEAD)$ ) { return 405; } location / { index index.html index.htm index.php; ssi on; } location ~ \.php { try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; #fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /srv/www/website1/$fastcgi_script_name; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # Redirect server error pages to the static page error_page 403 404 /error403.html; location = /error403.html { root /usr/share/nginx/html; } }
nginx.conf
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; gzip on; gzip_disable "msie6"; gzip_min_length 1100; gzip_vary on; gzip_proxied any; gzip_buffers 16 8k; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/x-font-ttf font/opentype application/vnd.ms-fontobject; server_tokens off; include /etc/nginx/conf.d/*.conf; # Load virtual host configuration files. include /etc/nginx/sites-enabled/*; # BLOCK SPAMMERS IP ADDRESSES include /etc/nginx/conf.d/blockips.conf; }
webroot dir的权限:
[root@soupcan nginx]# namei -om /srv/www/website1/ f: /srv/www/website1/ dr-xr-xr-x root root / drwxr-xr-x root root srv drwxrwxr-x brian nobody www drwxr-x--x brian nobody website1
发现CentOS 6.6和SELinux打破了nginx。 我仍然在寻找解决scheme,但这是事业。
解决scheme发布如下
这个问题是由CentOS从6.5升级到6.6以及SElinux如何允许内容types通过引起的。 有了这个升级,SElinux默认只允许httpd_t内容通过(类似于他们如何对待apache),并且因为我将所有webcontent存储在/srv/www/这些用户创build的文件夹中没有由系统自动设置内容标签。
要检查这个对你的webroot和/etc/nginx目录运行以下命令并比较内容types:
ls -Z /srv/www/
我已经运行了这些命令并重新启动了nginx ,现在一切正常。
grep nginx /var/log/audit/audit.log | audit2allow -m nginx > nginx.te grep nginx /var/log/audit/audit.log | audit2allow -M nginx semodule -i nginx.pp
林不知道这个SElinux模块做什么,但我发现它阅读这个post关于同样的问题。 我今天可能会试着支持它,因为我认为解决这个问题的第二件事实际上是有效的。
[09:15 AM] robotoverlord ~>chcon -Rv --type=httpd_sys_content_t /srv/www/ [09:15 AM] robotoverlord ~> ls -Z /srv/www/ drwxr-xr-x. www-data nobody unconfined_u:object_r:httpd_sys_content_t:s0 website1 [09:15 AM] robotoverlord ~>service nginx restart
有关SElinix内容标签的其他信息
问题解决了!
chmod ogw file
为文件,文件组和文件设置文件权限,每个文件是读(4),写(2),执行(1),如果想要
没有正确的读写权限
drwxr-x--x brian nobody website1
nginx是只读的,所以你必须让他进入!
cd /srv/ find . -type d -exec chmod 755 {} \;