Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Sunday, November 27, 2016

linux iptables 设置仅22、80端口可访问

【设置仅22、80端口可访问】 

通过命令 netstat -tnl 可以查看当前服务器打开了哪些端口 
Ssh代码  收藏代码
  1. netstat -tnl  


查看防火墙设置 
Ssh代码  收藏代码
  1. iptables -L -n   


开放22、80端口 
Ssh代码  收藏代码
  1. iptables -A INPUT -p tcp --dport 22 -j ACCEPT  
  2. iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT  
  3. iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT  
  4. iptables -A OUTPUT -p tcp --sport 80 -m state --state NEW,ESTABLISHED -j ACCEPT  


取消其他端口的访问规则 
Ssh代码  收藏代码
  1. iptables -P INPUT DROP  
  2. iptables -P FORWARD DROP  
  3. iptables -P OUTPUT DROP  



允许本地回环接口(即允许本机访问本机) 
Ssh代码  收藏代码
  1. iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT  

允许已建立的或相关连的通行(如数据库链接) 
Ssh代码  收藏代码
  1. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  

允许所有本机向外的访问 
Ssh代码  收藏代码
  1. iptables -A OUTPUT -j ACCEPT  



保存配置: 
Ssh代码  收藏代码
  1. service iptables save   


# 列出规则,供查看
iptables -L -n 
# stop iptables, 如果清空规则前没有停止,ssh 会断掉,必须重启系统
/etc/init.d/iptables stop
# 清空规则
iptables -F 
# 允许内网ip访问所有端口
iptables -A INPUT -s 192.168.1.0/24 -j ACCEPT 
# 允许本地回环接口(即运行本机访问本机)
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT 
# 允许访问22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT 
# 允许访问80端口
iptables -A INPUT -p tcp --dport 80 -j ACCEPT 
# 允许所有ip访问80端口
iptables -A INPUT -p tcp -s 0/0 --dport 80 -j ACCEPT 
# 允许本地发起的连接返回数据到任意端口。本地作为客户端可以发起到任何ip和端口的请求,这条规则确保能够收到返回
#------------------when conntrack unkonw error use this
# sudo /sbin/iptables -A OUTPUT -m state --state NEW,ESTABLISHED -j ACCEPT
# sudo /sbin/iptables -A INPUT  -m state --state ESTABLISHED -j ACCEPT
# sudo /sbin/iptables -A OUTPUT  -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT 
#---------------------------------------------------------------
iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT 
# 允许80端口返回数据
iptables -A OUTPUT  -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED -j ACCEPT 
# 允许返回数据给所有ip所有端口 允许所有本机向外的访问
iptables -A OUTPUT -j ACCEPT 
# 除上面允许的规则,抛弃所有INPUT请求 (注意:如果22端口未加入允许规则,SSH链接会直接断开。)
iptables -P INPUT DROP 
# 除上面允许的规则,抛弃所有FORWARD请求
iptables -P FORWARD DROP 
# 除上面允许的规则,抛弃所有OUTPUT请求
iptables -P OUTPUT DROP 
# 备份
iptables-save > /etc/iptables/iptables.rules 
# (cat /etc/sysconfig/iptables > /etc/iptables/iptables.rules )
# 保存(ArchLinux系统下的路径可能和其他系统下的路径不同)
sudo /etc/rc.d/init.d/iptables save
# 重新启动
sudo service iptables restart
# (/etc/init.d/iptables restart)
# 列出规则,供查看
iptables -L -n 

# iptables 安装后 iptables 命令无效,可能是因为该用户的PATH不包括/sbin和/usr/sbin, 可用 sudo /sbin/iptables 运行

Friday, April 10, 2015

在APACHE服务器上的访问方式上去除index.php


在APACHE服务器上的访问方式上去除index.php
 
下面我说下 apache 下 ,如何 去掉URL 里面的 index.php
例如: 你原来的路径是: localhost/index.php/index
改变后的路径是: localhost/index

1.httpd.conf配置文件中加载了mod_rewrite.so模块 //在APACHE里面去配置
#LoadModule rewrite_module modules/mod_rewrite.so把前面的警号去掉

2.在APACHE里面去配置 ,将里面的AllowOverride None都改为AllowOverride All

注意:修改之后一定要重启apache服务。


3.确保URL_MODEL设置为2, (url重写模式  注意:此方法在thinkphp里使用,其他感觉不需要)

在项目的配置文件里写

return Array(
‘URL_MODEL’ => ’2′,
);
4 .htaccess文件必须放到跟目录下

这个文件里面加:


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]

补充: windows 里面不能创建 .htaccess , 下面我说下创建方法
新建任何一个文件,然后打开, 点击另存为 (文件类型选择所有),这样就可以创建了