1、linux目錄下的文件怎麼通過瀏覽器輸入http的方式訪問文件?
這個需復要在本機搭建制有一個文本伺服器才可以,例如Apache等。
1、下載Apache軟體安裝到電腦上,將製作好的頁面放在網頁的根目錄下,Linux下為Apache安裝目錄下的htdocs文件夾下。
2、接下來就可以實現輸入IP/文件名稱訪問該網頁了。
補充知識:
Apache是世界使用排名第一的Web伺服器軟體。它可以運行在幾乎所有廣泛使用的計算機平台上,由於其跨平台和安全性被廣泛使用,是最流行的Web伺服器端軟體之一。它快速、可靠並且可通過簡單的API擴充,將Perl/Python等解釋器編譯到伺服器中。同時Apache音譯為阿帕奇,是北美印第安人的一個部落,叫阿帕奇族,在美國的西南部。也是一個基金會的名稱、一種武裝直升機等等。
2、HTTP從其他伺服器(WINDOWS或者LINUX系統)下載圖片
public static void doGetFile(String url, Header[] headers, String fileName) throws ServiceException {
if (url == null || url.length() <= 0) {
throw new ServiceException("Url can not be null.");
}
String temp = url.toLowerCase();
if (!temp.startsWith("http://") && !temp.startsWith("https://")) {
url = "http://" + url;
}
URI uri = URI.create(url);
url = uri.toASCIIString();
String host = uri.getHost();
if (headers == null) {
headers = prepareHeaders(host);
}
HttpGet httpMethod = null;
try {
// 初始化Http請求方法和參數
httpMethod = new HttpGet(url);
httpMethod.setHeaders(headers);
// 進行Http請求
HttpResponse response = SingletonHttpclient.getHttpClient().execute(httpMethod);
// 判斷請求是否成功
if (!isResponseSuccessStatus(response)) {
int status = response.getStatusLine().getStatusCode();
System.out.println("Http Satus:" + status + ",Url:" + url);
if (status >= 500 && status < 600)
throw new IOException("Remote service<" + url + "> respose a error, status:" + status);
return;
}
File file = new File(DOWNLOAD_BASE_PATH + fileName);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
FileOutputStream outputStream = new FileOutputStream(file);
InputStream inputStream = response.getEntity().getContent();
byte b[] = new byte[1024];
int j = 0;
while ((j = inputStream.read(b)) != -1) {
outputStream.write(b, 0, j);
}
outputStream.flush();
outputStream.close();
System.out.println("存儲了文件: " + file.getAbsolutePath());
} catch (Exception e) {
if (httpMethod != null) {
httpMethod.abort();
}
throw new ServiceException("get,error!url={" + url + "}");
}
}
3、linux下在配置WEB伺服器初期,由於經常需要編輯Apache配置文件,請為編輯該配置文件定義別名confighttp
直接給出命令
#vi /root/.bashrc
alias confighttp='vi /etc/httpd/conf/httpd.conf'
4、怎麼通過web方式下載放在linux伺服器上的文件
你啟動了http服務了么?
放在DocumentRoot的目錄下或其下的子目錄下,就可以專了
訪問方式屬 http://your_server_ip/your_file
5、linux centos怎麼搭建http文件伺服器
centos如果是建立文件伺服器一般使用ftp,安裝vsftp服務即可。
如果使用http的文件伺服器,可以使用apache的目錄瀏覽功能。
6、linux 如何禁止IP訪問http伺服器
Linux系統中,如果需要禁止特定ip地址訪問來保證系統的安全,只需通過操作iptalbes來實現,下面就給紹下Linux如何禁止某個ip地址訪問。
一、概述
這兩個文件是tcpd伺服器的配置文件,tcpd伺服器可以控制外部IP對本機服務的訪問。這兩個配置文件的格式如下:
#服務進程名:主機列表:當規則匹配時可選的命令操作
server_name:hosts-list[:command]
/etc/hosts.allow控制可以訪問本機的IP地址,/etc/hosts.deny控制禁止訪問本機的IP。如果兩個文件的配置有沖突,以/etc/hosts.deny為准。
/etc/hosts.allow和/etc/hosts.deny兩個文件是控制遠程訪問設置的,可以允許或者拒絕某個ip或者ip段的客戶訪問linux的某項服務。
比如SSH服務,通常只對管理員開放,那就可以禁用不必要的IP,而只開放管理員可能使用到的IP段。
二、配置
1、修改/etc/hosts.allow文件
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the 『/usr/sbin/tcpd』 server.
#
sshd:210.13.218.*:allow
sshd:222.77.15.*:allow
all:218.24.129.110 #表示接受110這個ip的所有請求!
in.telnetd:140.116.44.0/255.255.255.0
in.telnetd:140.116.79.0/255.255.255.0
in.telnetd:140.116.141.99
in.telnetd:LOCAL
smbd:192.168.0.0/255.255.255.0 #允許192.168.0.網段的IP訪問smbd服務
#sendmail:192.168.1.0/255.255.255.0
#pop3d:192.168.1.0/255.255.255.0
#swat:192.168.1.0/255.255.255.0
pptpd:all EXCEPT 192.168.0.0/255.255.255.0
httpd:all
vsftpd:all
以上寫法表示允許210和222兩個ip段連接sshd服務(這必然需要hosts.deny這個文件配合使用),當然:allow完全可以省略的。
ALL要害字匹配所有情況,EXCEPT匹配除了某些項之外的情況,PARANOID匹配你想控制的IP地址和它的域名不匹配時(域名偽裝)的情況。
2、修改/etc/hosts.deny文件
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the 『/usr/sbin/tcpd』 server.
#
# The portmap line is rendant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
sshd:all:deny
in.telnet:ALL
ALL:ALL EXCEPT 192.168.0.1/255.255.255.0,192.168.1.21,
202.10.5.0/255.255.255.0
注意看:sshd:all:deny表示拒絕了所有sshd遠程連接。:deny可以省略。
3、啟動服務。
注意修改完後:
#service xinetd restart
才能讓剛才的更改生效。
7、為什麼我的Linux里沒有 /etc/httpd/conf/http.conf 這個文件????
為什麼我的Linux里沒有 /etc/httpd/conf/http.conf 這個文件????
yum install httpd httpd-devel -y 安裝完阿帕奇就有了
ls -lh /etc/httpd.conf≠/etc/httpd/conf/http.conf
路徑要仔細看,一個符號差別就不是一個位置了
8、java web項目 在linux伺服器發送http post請求 中文亂碼
在進行post方式提交的時候,寫上request.setCharacterEncoding("UTF-8");
記住要在request設置提交參數之前設置字元編碼
祝:生活愉快
9、如何搭建像linux公社資源站那樣的Http 文件伺服器, 附帶公社http://linux.linuxidc.com/
這是http伺服器的基本功能,如果不設置index這類文件,就可以顯示目錄列表。
10、linux 如何禁止IP訪問http伺服器
Linux系統中,如果需要禁止特定ip地址訪問來保證系統的安全,只需通過操作iptalbes來實現,下面就給紹下Linux如何禁止某個ip地址訪問。
一、概述
這兩個文件是tcpd伺服器的配置文件,tcpd伺服器可以控制外部IP對本機服務的訪問。這兩個配置文件的格式如下:
#服務進程名:主機列表:當規則匹配時可選的命令操作
server_name:hosts-list[:command]
/etc/hosts.allow控制可以訪問本機的IP地址,/etc/hosts.deny控制禁止訪問本機的IP。如果兩個文件的配置有沖突,以/etc/hosts.deny為准。
/etc/hosts.allow和/etc/hosts.deny兩個文件是控制遠程訪問設置的,可以允許或者拒絕某個ip或者ip段的客戶訪問linux的某項服務。
比如SSH服務,通常只對管理員開放,那就可以禁用不必要的IP,而只開放管理員可能使用到的IP段。
二、配置
1、修改/etc/hosts.allow文件
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the 『/usr/sbin/tcpd』 server.
#
sshd:210.13.218.*:allow
sshd:222.77.15.*:allow
all:218.24.129.110 #表示接受110這個ip的所有請求!
in.telnetd:140.116.44.0/255.255.255.0
in.telnetd:140.116.79.0/255.255.255.0
in.telnetd:140.116.141.99
in.telnetd:LOCAL
smbd:192.168.0.0/255.255.255.0 #允許192.168.0.網段的IP訪問smbd服務
#sendmail:192.168.1.0/255.255.255.0
#pop3d:192.168.1.0/255.255.255.0
#swat:192.168.1.0/255.255.255.0
pptpd:all EXCEPT 192.168.0.0/255.255.255.0
httpd:all
vsftpd:all
以上寫法表示允許210和222兩個ip段連接sshd服務(這必然需要hosts.deny這個文件配合使用),當然:allow完全可以省略的。
ALL要害字匹配所有情況,EXCEPT匹配除了某些項之外的情況,PARANOID匹配你想控制的IP地址和它的域名不匹配時(域名偽裝)的情況。
2、修改/etc/hosts.deny文件
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the 『/usr/sbin/tcpd』 server.
#
# The portmap line is rendant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
sshd:all:deny
in.telnet:ALL
ALL:ALL EXCEPT 192.168.0.1/255.255.255.0,192.168.1.21,
202.10.5.0/255.255.255.0
注意看:sshd:all:deny表示拒絕了所有sshd遠程連接。:deny可以省略。
3、啟動服務。
注意修改完後:
#service xinetd restart
才能讓剛才的更改生效。