如何提高Nginx的安全与性能
主要展示在nginx中配置x-frame-options、x-xss-protection、 x-content-type-options、strict-transport-security、https等安全配置。
nginx.conf配置如下
# 不要将nginx版本号在错误页面或服务器头部中显示 server_tokens off; #不允许页面从框架frame 或 iframe中显示,这样能避免clickjacking # http://en.wikipedia.org/wiki/clickjacking # 如果你允许[i]frames, 你能使用sameorigin 或在allow-from中设置你的允许的url # https://developer.mozilla.org/en-us/docs/http/x-frame-options add_header x-frame-options sameorigin; #当你的网站是用户提供的内容比如博客论坛等,使用 x-content-type-options: nosniff 头部, # 这是为了失效某些浏览器的内容类型探嗅 # https://www.owasp.org/index.php/list_of_useful_http_headers # 当前支持ie > 8以上版本 http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-2-update.aspx # http://msdn.microsoft.com/en-us/library/ie/gg622941(v=vs.85).aspx #firefox https://bugzilla.mozilla.org/show_bug.cgi?id=471020 add_header x-content-type-options nosniff; # 防止跨站脚本 cross-site scripting (xss) ,目前已经被大多数浏览器支持 #默认是激活的,如果被用户失效,可以使用这个配置激活。 # https://www.owasp.org/index.php/list_of_useful_http_headers add_header x-xss-protection "1; mode=block"; #激活内容安全策略content security policy (csp) ,大部分浏览器支持 # 告诉浏览器只能从本域名和你显式指定的网址下载脚本。 # http://www.html5rocks.com/en/tutorials/security/content-security-policy/#inline-code-considered-harmful add_header content-security-policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none'"; server { listen 443 ssl default deferred; server_name .forgott.com; ssl_certificate /etc/nginx/ssl/star_forgott_com.crt; ssl_certificate_key /etc/nginx/ssl/star_forgott_com.key; #激活会话重续提高https性能 # http://vincent.bernat.im/en/blog/2011-ssl-session-reuse-rfc5077.html ssl_session_cache shared:ssl:50m; ssl_session_timeout 5m; # diffie-hellman parameter for dhe ciphersuites, recommended 2048 bits ssl_dhparam /etc/nginx/ssl/dhparam.pem; #激活服务器端保护免于beast 攻击 # http://blog.ivanristic.com/2013/09/is-beast-still-a-threat.html ssl_prefer_server_ciphers on; # 失效 sslv3(自nginx 0.8.19默认激活) http://en.wikipedia.org/wiki/secure_sockets_layer#ssl_3.0 ssl_protocols tlsv1 tlsv1.1 tlsv1.2; # 为保密性和相容性选择密码 # http://blog.ivanristic.com/2013/08/configuring-apache-nginx-and-openssl-for-forward-secrecy.html ssl_ciphers "ecdhe-rsa-aes256-gcm-sha384:ecdhe-rsa-aes128-gcm-sha256:dhe-rsa-aes256-gcm-sha384:dhe-rsa-aes128-gcm-sha256:ecdhe-rsa-aes256-sha384:ecdhe-rsa-aes128-sha256:ecdhe-rsa-aes256-sha:ecdhe-rsa-aes128-sha:dhe-rsa-aes256-sha256:dhe-rsa-aes128-sha256:dhe-rsa-aes256-sha:dhe-rsa-aes128-sha:ecdhe-rsa-des-cbc3-sha:edh-rsa-des-cbc3-sha:aes256-gcm-sha384:aes128-gcm-sha256:aes256-sha256:aes128-sha256:aes256-sha:aes128-sha:des-cbc3-sha:high:!anull:!enull:!export:!des:!md5:!psk:!rc4"; # 激活ocsp stapling (一种机制:一个网站可以保护隐私可扩展的方式传达的证书撤销信息给访问者)mechanism by which a site can convey certificate revocation information to visitors in a privacy-preserving, scalable manner) # http://blog.mozilla.org/security/2013/07/29/ocsp-stapling-in-firefox/ resolver 8.8.8.8; ssl_stapling on; ssl_trusted_certificate /etc/nginx/ssl/star_forgott_com.crt; # 配置激活hsts(http strict transport security) https://developer.mozilla.org/en-us/docs/security/http_strict_transport_security #避免ssl stripping https://en.wikipedia.org/wiki/ssl_stripping#ssl_stripping add_header strict-transport-security "max-age=31536000; includesubdomains;"; # ... the rest of your configuration } # redirect all http traffic to https server { listen 80; server_name .forgott.com; return 301 https://$host$request_uri; }
以上是如何提高Nginx的安全与性能的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

要让 Tomcat 服务器对外网访问,需要:修改 Tomcat 配置文件,允许外部连接。添加防火墙规则,允许访问 Tomcat 服务器端口。创建 DNS 记录,将域名指向 Tomcat 服务器公有 IP。可选:使用反向代理提升安全性和性能。可选:设置 HTTPS 以提高安全性。

Nginx 的启动和停止命令分别为 nginx 和 nginx -s quit。启动命令直接启动服务器,而停止命令优雅地关闭服务器,允许所有当前请求处理完毕。其他可用停止信号包括 stop 和 reload。

ThinkPHP Framework 的本地运行步骤:下载并解压 ThinkPHP Framework 到本地目录。创建虚拟主机(可选),指向 ThinkPHP 根目录。配置数据库连接参数。启动 Web 服务器。初始化 ThinkPHP 应用程序。访问 ThinkPHP 应用程序 URL 运行。

要解决 "Welcome to nginx!" 错误,需要检查虚拟主机配置,启用虚拟主机,重新加载 Nginx,如果无法找到虚拟主机配置文件,则创建默认页面并重新加载 Nginx,这样错误消息将消失,网站将正常显示。

Node.js 项目的服务器部署步骤:准备部署环境:获取服务器访问权限、安装 Node.js、设置 Git 存储库。构建应用程序:使用 npm run build 生成可部署代码和依赖项。上传代码到服务器:通过 Git 或文件传输协议。安装依赖项:SSH 登录服务器并使用 npm install 安装应用程序依赖项。启动应用程序:使用 node index.js 等命令启动应用程序,或使用 pm2 等进程管理器。配置反向代理(可选):使用 Nginx 或 Apache 等反向代理路由流量到应用程

要注册 phpMyAdmin,需要先创建 MySQL 用户并授予其权限,然后下载、安装和配置 phpMyAdmin,最后登录到 phpMyAdmin 以管理数据库。

访问网站出现 nginx,原因可能是:服务器维护、服务器繁忙、浏览器缓存、DNS 问题、防火墙阻止、网站错误配置、网络连接问题或网站已关闭。尝试以下解决方案:等待维护结束、非高峰时段访问、清除浏览器缓存、刷新 DNS 缓存、禁用防火墙或防病毒软件、联系网站管理员、检查网络连接或使用搜索引擎或 Web 存档查找其他网站副本。如果问题仍然存在,请与网站管理员联系。

Docker 环境中容器通信有五种方法:共享网络、Docker Compose、网络代理、共享卷、消息队列。根据隔离性和安全性需求,选择最合适的通信方法,例如利用 Docker Compose 简化连接或使用网络代理提高隔离性。
