打开nginx.conf配置文件,把以下代码放到http{}里

server {
listen 8866;#端口
#代理本地静态文件
location / {#浏览器访问路径 ip:8866/
root /opt/softwares/;#文件服务器路径
index index1.html index.htm;#文件名如果找不到index1.html 就找index.htm
}
#代理其他网站页面
location /ccc.html {#浏览器访问路径 ip:8866/ccc.html
proxy_pass https://www.chinanews.com/gn/2023/03-09/9968330.shtml;
}
}
ip禁用,如果不让某个ip访问,我仅需要再location下加deny ip; 我们用自己本地IP来测试,加上之后重启nginx
server {
listen 8866;#端口
#IP禁用案例
location /ccc.html {#浏览器访问路径 ip:8866/ccc.html
deny 本地ip;
proxy_pass https://www.chinanews.com/gn/2023/03-09/9968330.shtml;
}
}
我们再次访问 ip:8866/ccc.html,就会提示403

文章介绍了如何在Nginx配置文件中设置代理本地静态文件和外部网站页面,并展示了如何通过在location块中添加deny指令来禁止特定IP访问,以本地IP为例,当尝试访问被禁止的页面时,会收到403Forbidden的响应。
1973

被折叠的 条评论
为什么被折叠?



