Nginx限制IP,限制目录访问的设置
location /private/ {
allow 192.168.1.0/24;
deny all;
}
location ~ ^/private/.*\.php$ {
allow 192.168.1.0/24;
deny all;
include [...]
NGINX安装,最新下载,配置,优化等
location /private/ {
allow 192.168.1.0/24;
deny all;
}
location ~ ^/private/.*\.php$ {
allow 192.168.1.0/24;
deny all;
include [...]
在你需要设置404页面的server段里添加:
server
{
listen 80;
server_name www.unixbeta.com;
index index.html index.htm index.php;
root [...]
今天要在Nginx上设置禁止通过IP访问服务器,只能通过域名访问,这样做是为了避免别人把未备案的域名解析到自己的服务器IP而导致服务器被断网,从网络上搜到以下解决方案:
==============================
nginx的默认虚拟主机在用户通过IP访问,或者通过未设置的域名访问(比如有人把他自己的域名指向了你的ip)的时候生效
最关键的一点是,在server的设置里面添加这一行:
listen 80 default;
后面的default参数表示这个是默认虚拟主机。
这个设置非常有用。
比如别人通过ip或者未知域名访问你的网站的时候,你希望禁止显示任何有效内容,可以给他返回500.
目前国内很多机房都要求网站主关闭空主机头,防止未备案的域名指向过来造成麻烦。就可以这样设置:
server {
listen 80 default;
return 500;
}
也可以把这些流量收集起来,导入到自己的网站,只要做以下跳转设置就可以:
server {
listen 80 default;
rewrite ^(.*) http://www.mydomain.com [...]
你还记得apache下打开目录浏览功能的参数吗
Options FollowSymLinks
AllowOverride None
Options Indexes #就加这句就可以了,目录按需要选择
#就加这句就可以了,目录按需要选择
在Nginx下默认是不允许列出整个目录的。如需此功能,
先打开nginx.conf文件,在location server 或 http段中加入
autoindex on;
另外两个参数最好也加上去:
autoindex_exact_size off;
默认为on,显示出文件的确切大小,单位是bytes。
改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
autoindex_localtime on;
默认为off,显示的文件时间为GMT时间。
注意:改为on后,显示的文件时间为文件的服务器时间
server{
listen 80;
servername www.A.com;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
root /home/www/;
}
详细参照:http://wiki.nginx.org/NginxChsHttpAutoindexModule
7,修改php.ini文件
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = “./”
修改为extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
并在此行后增加以下几行,然后保存:
extension = “memcache.so”
extension = “pdo_mysql.so”
再查找 output_buffering = Off
修改为output_buffering = On
自动修改:可执行以下shell命令,自动完成对php.ini文件的修改:
sed -i ’s#extension_dir = “./”#extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”\nextension = “memcache.so”\nextension = “pdo_mysql.so”\n#’ /usr/local/php/etc/php.ini
sed -i ’s#output_buffering = Off#output_buffering = [...]