当前位置:首页 > Linux

创建软链接及解决项目内的软链访问报404的问题

canca8年前 (2017-09-16)Linux783

实例:ln -s /home/gamestat    /gamestat

 

linux下的软链接类似于windows下的快捷方式

 

ln -s a b 中的 a 就是源文件,b是链接文件名,其作用是当进入b目录,实际上是链接进入了a目录

如上面的示例,当我们执行命令   cd /gamestat/的时候  实际上是进入了 /home/gamestat/

 

值得注意的是执行命令的时候,应该是a目录已经建立,目录b没有建立。我最开始操作的是也把b目录给建立了,结果就不对了


[root@iZbp1eqd771ku506fyee6yZ storage-sc]# ln -s /data/resource/ueditor ./ueditor
[root@iZbp1eqd771ku506fyee6yZ storage-sc]# ls
config.json  controller.jsp  index.jsp  META-INF  ueditor  WEB-INF
[root@iZbp1eqd771ku506fyee6yZ storage-sc]# cd ueditor/



特别需要说明的是,我们在项目下创建的软链默认是不能被外界访问的,要解决这个问题我们得修改tomcat的配置文件,但是修改之前,我们得先看看我们的tomcat的版本是多少,如下所示,可以看到我使用的tomcat的版本是9.0.0

[root@dev bin]# ./version.sh 
Using CATALINA_BASE:   /root/tomcat/server/storage1
Using CATALINA_HOME:   /root/tomcat/server/storage1
Using CATALINA_TMPDIR: /root/tomcat/server/storage1/temp
Using JRE_HOME:        /home/data/jdk1.8.0_102
Using CLASSPATH:       /root/tomcat/server/storage1/bin/bootstrap.jar:/root/tomcat/server/storage1/bin/tomcat-juli.jar
Server version: Apache Tomcat/9.0.0.M10
Server built:   Aug 31 2016 15:00:21 UTC
Server number:  9.0.0.0
OS Name:        Linux
OS Version:     3.10.0-327.36.3.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_102-b14
JVM Vendor:     Oracle Corporation
[root@dev bin]# 

 下面我们到tomcat下找到context.xml文件,如下所示。
[root@dev storage1]# ls
bin  conf  lib  LICENSE  logs  NOTICE  RELEASE-NOTES  RUNNING.txt  SESSIONS.ser  storage-sc  temp  webapps  work
[root@dev storage1]# cd conf
[root@dev conf]# ls
Catalina  catalina.policy  catalina.properties  context.xml  jaspic-providers.xml  jaspic-providers.xsd  logging.properties  server.xml  tomcat-users.xml  tomcat-users.xsd  web.xml
[root@dev conf]# 

 不同版本的tomcat对context.xml的修改是不一样的,如果是tomcat7及以下版本,那么修改如下,也就是在<Context 后添加了allowLinking="true"这么一句话。
<Context allowLinking="true">
    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>


    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
</Context>

如果是tomcat8及其以上版本的话,修改如下,就是在<Context>的下方添加了 一行<Resources allowLinking="true" />,这样就可以访问了!!

<Context>
    <Resources allowLinking="true" />
    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>


    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
</Context>



 

删除软链接:

   rm -rf  b  注意不是rm -rf  b/

 

ln  a b 是建立硬链接

建立链接的使用方法如下:

 

 

[root@WEB_YQ_64_79 /]# ln --help

Usage: ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)

  or:  ln [OPTION]... TARGET                  (2nd form)

  or:  ln [OPTION]... TARGET... DIRECTORY     (3rd form)

  or:  ln [OPTION]... -t DIRECTORY TARGET...  (4th form)

In the 1st form, create a link to TARGET with the name LINK_NAME.

In the 2nd form, create a link to TARGET in the current directory.

In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.

Create hard links by default, symbolic links with --symbolic.

When creating hard links, each TARGET must exist.

 

Mandatory arguments to long options are mandatory for short options too.

      --backup[=CONTROL]      make a backup of each existing destination file

  -b                          like --backup but does not accept an argument

  -d, -F, --directory         allow the superuser to attempt to hard link

                                directories (note: will probably fail due to

                                system restrictions, even for the superuser)

  -f, --force                 remove existing destination files

  -n, --no-dereference        treat destination that is a symlink to a

                                directory as if it were a normal file

  -i, --interactive           prompt whether to remove destinations

  -s, --symbolic              make symbolic links instead of hard links

  -S, --suffix=SUFFIX         override the usual backup suffix

  -t, --target-directory=DIRECTORY  specify the DIRECTORY in which to create

                                the links

  -T, --no-target-directory   treat LINK_NAME as a normal file

  -v, --verbose               print name of each file before linking

      --help     display this help and exit

      --version  output version information and exit

 

The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.

The version control method may be selected via the --backup option or through

the VERSION_CONTROL environment variable.  Here are the values:

 

  none, off       never make backups (even if --backup is given)

  numbered, t     make numbered backups

  existing, nil   numbered if numbered backups exist, simple otherwise

  simple, never   always make simple backups

 

Report bugs to .

扫描二维码推送至手机访问。

版权声明:本文由Ant.Master's Blog发布,如需转载请注明出处。

本文链接:https://iant.work/post/13.html

标签: Linux
分享给朋友:

“创建软链接及解决项目内的软链访问报404的问题” 的相关文章

Linux 安装Apache

本以为Apache的编译安装很简单,其实不然;  以前的环境下编译报错很少 ,但这次不行了  提示configure: error: APR not found. Please read the documentation.  经网上查阅资料才知道这是Apac…

linux下U盘无法卸载的问题

实用U盘过程中MOUNT之后,操作完毕,想UMOUNT,然后拔U盘,可是,总是无法UMOUNT,老是显示DEVICE IS BUSY,确认没有窗口对U盘挂载点进行操作或游览了。有两种方法:一、1.#fuser -m /mnt/usb(你挂载的U盘)查找该程序的进程,然后kill掉...…

centos 7 crontab定时器及开机自启

crontab 建议直接采用centos7 自带得cronteb包,定时器:就是定时去执行干某一件事在这里我以脚本为媒介1 当然是创建一个脚本,创建目录随意但是你一定要记得。。直接通过vi来创建一个test.sh脚本!…

centos7 手动修改dns

方法一:vim /etc/resolv.conf…

armbian修改为中文环境,解决中文乱码

step1:输入 dpkg-reconfigure locales…

Linux修改用户名

Linux将用户名修改后,还需要修改 组名+家目录+UID这只会更改用户名,而其他的东西,比如用户组,家目录,UID 等都保持不变。1、修改用户名$ usermod -l 新用户  旧用户这只会更改用户名,而其他的东西,比如用户组、家目录、ID 等都…

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。