Painstakingly
Built WebsiteIt can be frustrating when the articles you write are mirrored and referenced by other websites. Previously, I shared
methods for preventing hotlinking in Baota Panel and LNMP, but these methods cannot prevent others from embedding your website's content using iframe frames. So, how can you prevent other websites from referencing your site's content via iframe frames? The solution is as follows:
Restrict References from Other Websites via X-Frame-Options
The X-Frame-Options HTTP response header is used to instruct the browser whether a page can be displayed within a <frame>, <iframe>, <embed>, or <object>. Websites can avoid clickjacking attacks by ensuring they are not embedded into other sites.
X-Frame-Options has the following three values available: X-Frame-Options:
deny// Prohibits framing from all domains X-Frame-Options:
sameorigin// Only the same domain can frame X-Frame-Options:
allow-fromhttps://example.com/ // Only the specified domain can frame Typically, we only need to add X-Frame-Options: sameorigin to solve the issue.
Implementation Methods for nginx and Baota Panel
If your server uses nginx or Baota Panel, you can implement the addition of X-Frame-Options: sameorigin using the following method. In your virtual host's nginx configuration file, add the following code (for Baota users, the operation path is: Website - Settings - Configuration File)
add_header X-Frame-Options SAMEORIGIN always;
Add the code above the line containing the root directive, as shown below:
listen 80;
listen 443 ssl http2;
server_name blog.naibabiji.com;
index index.html index.htm default.html default.htm index.php default.php;
add_header X-Frame-Options SAMEORIGIN always;
root /www/wwwroot/blog.naibabiji.com;
After adding, restart the nginx service to see the effect. The command to restart nginx for the LNMP one-click installation package is: /etc/init.d/nginx restart The path to restart nginx in Baota Panel is: App Store - Search for nginx - Click on nginx - Restart
Other Setting Methods
If you are not using the nginx service, please refer to the instructions in the following article and follow the steps accordingly.
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/X-Frame-OptionsThe above content teaches you how to deal with the issue of your website being framed by others during the website building process. If you have other questions, feel free to leave a comment for discussion.
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.