当前位置:   首页安装配置香港主机Nginx常见问题解决办法_匹配解决方法

香港主机Nginx常见问题解决办法_匹配解决方法

发布日期:2022-02-11 16:41 | 文章来源:脚本之家

Yingsoo Host给大家详细整理了香港主机nginx常见的问题以及对应问题的处理办法,有需要的朋友参考一下吧。以下就是我们整理的nginx常见的问题,解决办法我们例举了1-2种,大家可以都测试下。常见问题问题一:相同server_name多个虚拟主机优先级访问 server{ listen 80; server_name server1; location{...}}server{ listen 80; server_name server2; location{...}}解决方法:配置两个conf文件:server1.conf 和 server2.conf根据Linux系统中文件顺序读取问题二:location匹配优先级location = /code1/ { rewrite ^(.*)$ /code1/index.html break;}location ~ /code.* { rewrite ^(.*)$ /code3/index.html break;}location ^~ /code { rewrite ^(.*)$ /code2/index.html break;}知识填坑:=:进行普通字符精确匹配,完全匹配^~:普通字符匹配,使用前缀匹配~ \~*:表示执行一个正则匹配()解决方法:根据匹配找到最优匹配优先级:完全匹配正则匹配前缀匹配问题三:try_files使用location / { try_files $uri $uri/ /index.html;}解决方法:按顺序检查文件是否存在问题四:Nginx的alias和root区别location /request_path/img/ { root /local_path/img/;}location /request_path/img/ { alias /local_path/img/;}解决方法:root设置,最终请求的路径为/local_path/img/request_path/img/alias设置,最终请求为/local_path/img/问题五:通过多层代理,传递用户真实IP解决方法:set x_real_ip=$remote_addr$x_real_ip=真实IP性能优化问题优化考虑点:当前系统结构瓶颈,如观察指标、压力测试了解业务模式,如接口业务类型、系统层次化结构性能与安全接口压力测试工具:ab安装:yum install httpd-tools使用:ab -n 2000 -c 20 http://127.0.0.1/nginx关于系统的优化点:网络、系统、服务、程序、数据库控制文件句柄数量,文件句柄就是一个索引CPU亲和,使进程不会在处理器间频繁迁移,减少性能损耗vim /etc/nginx/nginx.confuser nginx;worker_processes 16;worker_cpu_affinity auto;worker_rlimit_nofile 15535;events{ use epoll; worker_connections 10240;}http{ include /etc/nginx/mime.types; default_type application/octet-stream; #Charset charset utf-8; log_format main ''; access_log /var/log/nginx/access.log main; #Core module sendfile on; keepalive_timeout 65; #Gzip module gzip on; gzip_disable "MSIE [1-6]\."; gzip_http_version 1.1; #Virtal server include /etc/nginx/conf.d/*.conf;}nginx安全问题及防范策略恶意行为问题:爬虫行为和恶意抓取、资源盗用解决方法:基础防盗链功能:不让恶意用户轻易的爬取网站对外数据secure_link_module模块:对数据安全性提高加密验证和失效性,对一些重要数据使用 。

版权声明:本站部分内容来源于网友推荐、互联网收集整理而来,仅供学习参考,不代表本站立场,如有内容涉嫌侵权,请联系alex-e#qq.com处理。

联系我们
关于使用场景和技术架构的更多咨询,请联系我们的销售和技术支持团队。
Yingsoo Host

在线
客服

在线客服:7*24小时在线

客服
热线

400-630-3752
7*24小时客服服务热线

关注
微信

关注官方微信
顶部