实现windows浏览器远程浏览访问linux服务器网站中的一个目录

      本人比较笨,经过两个小时的摸索和本地虚拟机的测试,终于实现在wind浏览器上访问nginx服务下目录的浏览。期间也想过询问大神,但想一想自己经过实验的得出的成果才是自己学到的,把这个分享给大家。其中网上的这个方法一大堆但很少有用到的。

     功能介绍:在nginx目录中,目录列表是默认自动关闭的;需要打开的nginx的目录列表功能需要手动配置。才可以进行访问。

步骤一:打开nginx配置文件,根据自己的nginx路径进行访问

         

[root@abc ~]# cd /usr/local/nginx/conf/vhost/test.conf

 server {

   listen 80;

   server_name localhost;            //服务器ip地址

   root /var/www/html;           

   index index.html;

 

   location / {                       //红色字体为添加的内容

   autoindex on;

   autoindex_exact_size off;

   autoindex_localtime on;           

   }

 

   location /images {

      root   /var/www/html/shibo;

      autoindex on;              //必须加上这一句,防止出现403错误

        }

 

 

}

保存:wq 退出!

重启nginx : systemctl restart nginx.service -s reload.

 

如上的设置,要想设置nginx的目录浏览功能,必须要打开下面这个参数
autoindex on;

此外,另外两个参数最好也加上去:
autoindex_exact_size off;
默认为on,显示出文件的确切大小,单位是bytes。
改为off后,显示出文件的大概大小,单位是kB或者MB或者GB

autoindex_localtime on;
默认为off,显示的文件时间为GMT时间。
改为on后,显示的文件时间为文件的服务器时间

设置完成。

(二)设置验证访问的目录浏览 (摘自https://www.cnblogs.com/kevingrace/p/6244812.html)

 

创建类htpasswd文件(如果没有htpasswd命令,可通过"yum install -y *htpasswd*"或"yum install -y httpd")
[root@wangshibo ~]# htpasswd -c /usr/local/nginx/conf/auth_password wangshibo //会被要求输入两次密码
[root@wangshibo ~]# cat /usr/local/nginx/conf/auth_password
wangshibo:$awe1$I2FIVtPG$I51oSU4eatH.tJdnmxtg67

Nginx配置中添加auth认证配置
[root@wangshibo ~]# vim /usr/local/nginx/conf/vhost/test.conf
......
location ^~ /soft/ {
     root /var/www/html;              //此处为soft的上一级目录。注意root和alias虚拟目录设置区别
     autoindex on;
     autoindex_exact_size off;
     autoindex_localtime on;
     auth_basic "MyPath Authorized";                    //为提示信息,可以自行修改;会出现在第一次访问Nginx站点的弹出框内
     auth_basic_user_file /usr/local/nginx/conf/auth_password;                  //最好跟htpasswd文件的全路径
}

重启nginx服务
[root@wangshibo ~]# /usr/local/nginx/sbin/nginx -s reload

这时候访问站点的soft目录时就会被要求输入用户名和密码:

需要特别注意的是:
加上认证之后该目录下的php文件将不会被解析,会运行下载。
如果要使其能够解析php可以,可将上面的配置改为:

1

2

3

4

5

6

7

8

9

10

11

12

location ^~ /soft/ {

   location ~ \.php$ {                           //或者是location ~ .*\.(php|php5)?$ {

      root   /var/www/html;

      fastcgi_pass   127.0.0.1:9000;

      fastcgi_read_timeout 300;

      fastcgi_index  index.php;

      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;;

      include        fastcgi.conf;

  }

      auth_basic "Authorized users only";

      auth_basic_user_file /usr/local/nginx/conf/auth_password;

}

nginx运行目录浏览后,就可以利用wget进行文件远程传输了(只针对文件,因为在http下只能文件访问,直接跟url访问目录是404)
比如:
[root@wangshibo ~]# cat /var/www/html/aa/haha
this is test file

-----------------------------------------------------------------------版本隐藏设置-------------------------------------------------------------------------------------------

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

----------------------------------------------------------------------------

1)在nginx下禁止使用ip访问,将使用ip访问的流量重定向到公司的官网上。

在vhost下重新编辑一个default.conf 文件,如下:

server {

    listen 80 default_server;

#    server_name _;

#    return 500;

    rewrite ^(.*) https://www.wangshibo.com permanent;

}

 

然后重启nginx即可!

----------------------------------

下面就是直接紧张ip访问了

server {

    listen 80 default_server;

    server_name _;

    return 500;

}

----------------------------------

 

2)隐藏nginx的版本号

直接在nginx.conf文件中的http{}里面添加:

server_tokens off;

 

重启nginx服务即可!

curl -i http://www.wangshibo.com    测试访问就会发现nginx的header信息中已没有版本信息了(-i参数)

 

3)隐藏tomcat的版本号

# /data/tomcat8/bin/version.sh        #查看版本号信息

Using CATALINA_BASE:   /data/tomcat8

Using CATALINA_HOME:   /data/tomcat8

Using CATALINA_TMPDIR: /data/tomcat8/temp

Using JRE_HOME:        /usr/lib/jvm/java-1.7.0-openjdk.x86_64

Using CLASSPATH:       /data/tomcat8/bin/bootstrap.jar:/data/tomcat8/bin/tomcat-juli.jar

Server version: Apache Tomcat/8.5.15

Server built:   May 5 2017 11:03:04 UTC

Server number:  8.5.15.0

OS Name:        Linux

OS Version:     2.6.32-696.3.2.el6.x86_64

Architecture:   amd64

JVM Version:    1.7.0_141-mockbuild_2017_05_09_14_20-b00

JVM Vendor:     Oracle Corporation

 

# cp -r /data/tomcat8 /data/tomcat8.bak

# cd /data/tomcat8/lib

# jar xf catalina.jar

# vim org/apache/catalina/util/ServerInfo.properties

server.info=Apache Tomcat        //修改成这样

server.number=                 //清空

server.built=                  //清空

 

# jar cf catalina.jar org     //再次打包覆盖

# ll catalina.jar

# /data/tomcat8/bin/version.sh        //发现tomcat的版本信息已被隐藏

Using CATALINA_BASE:   /data/tomcat8

Using CATALINA_HOME:   /data/tomcat8

Using CATALINA_TMPDIR: /data/tomcat8/temp

Using JRE_HOME:        /usr/lib/jvm/java-1.7.0-openjdk.x86_64

Using CLASSPATH:       /data/tomcat8/bin/bootstrap.jar:/data/tomcat8/bin/tomcat-juli.jar

Server version: Apache Tomcat          

Server built:  

Server number: 

OS Name:        Linux

OS Version:     2.6.32-696.3.2.el6.x86_64

Architecture:   amd64

JVM Version:    1.7.0_141-mockbuild_2017_05_09_14_20-b00

JVM Vendor:     Oracle Corporation

 

4)nginx-status开启状态查看功能及参数说明

本模块在编译的时候默认是不编译的,如果是从源码编译安装的nginx,那么需要在./configure编译的时候加上对应的模块--with-http_stub_status_module

使用 ./configure --help 能看到更多的模块支持,然后编译安装即可。

[root@www vhosts]# /usr/local/nginx/sbin/nginx -V      //使用这个命令可以查看在编译安装的时候使用了哪些模块

nginx version: nginx/1.8.1

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

built with OpenSSL 1.0.1g 7 Apr 2014 (running with OpenSSL 1.0.1e-fips 11 Feb 2013)

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre

 

接下来需要在nginx的配置文件中增加这个配置项。打开nginx的配置文件 nginx.conf,在server段里面增加如下的内容:

  

       location /nginx-status {

       stub_status on;

       access_log off;

       #allow 127.0.0.1;                       

       #deny all;

}

 

重启nginx服务后,访问:

# curl http://127.0.0.1/nginx-status

Active connections: 11921

server accepts handled requests

113    113     116

Reading: 0 Writing: 7 Waiting: 42

 

active connections – 活跃的连接数量

server accepts handled requests — 总共处理了113个连接 , 成功创建113次握手, 总共处理了116个请求

reading — 读取客户端的连接数.

writing — 响应数据到客户端的数量

waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值