Path traversal attack exploits improper handling of filenames in a website’s query string. Typically, the hackers are looking for private files not intended for user browsing, files that may contain sensitive data (payment data, server configuration elements, etc).
A way to prevent this kind of attack is by segregation. Public and private files are kept in different locations. For examples, the public files are on server A, the private files would be either in a secure partition on server A or on a secure file on server B.
Another way to prevent is to restrict permissions on the server. The principle of least privilege – systems operate with the least amount of privilege necessary.
Other measures are: keeping the server OS up-to-date, sanitizing paths for illegal character patterns or not relying on user input for filenames.