Articles of nginx

nginx防火墙与cloudflare

我想防止在我的网站hotlingking。 不过,我也有cloudflare服务我的网站。 我不想使用cloudflare盗链保护function,因为它不能排除我允许图像链接的外部域(以及将图像redirect到热链接拒绝的图像)。 因此,我想防止在我的服务器级别的盗链。 问题是,当我在我的服务器启用它,cloudflare将redirect到热链接拒绝的图像,无论什么是域,其中包括我自己的域。 这是我使用的代码: location ~* \.(gif|png|jpe?g)$ { # prevent hotlink valid_referers none blocked ~.google. ~.bing. ~.yahoo. allowed-domain.com, server_names ~($host); if ($invalid_referer) { rewrite (.*) /static/images/hotlink-denied.jpg redirect; # drop the 'redirect' flag for redirect without URL change (internal rewrite) } } location = /static/images/hotlink-denied.jpg { } 有没有办法绕过图像上的云雾?

connect()失败(111:连接被拒绝),同时连接上游

[error] 7697#7697: *100335 connect() failed (111: Connection refused) while connecting to upstream, client: XXX.XXX.XXX.XXX, server: v4.domain.com, request: "GET /socket.io/?__sails_io_sdk_version=0.13.8&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=Luvcibs HTTP/1.1", upstream: "http://127.0.0.1:1338/socket.io/?__sails_io_sdk_version=0.13.8&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=Luvcibs", host: "v4.domain.com", referrer: "http://v4.domain.com/?ct=t(Flash_Sals_Videotoolz_copy_05_12_29_2016)&mc_cid=404a630ab2&mc_eid=c44f7937fe" [error] 7700#7700: *101735 connect() failed (111: Connection refused) while connecting to upstream, client: XX.XX.XX.XX, server: v4.domain.com, request: "GET /socket.io/?__sails_io_sdk_version=0.13.8&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=LuvciVy HTTP/1.1", upstream: "http://127.0.0.1:1338/socket.io/?__sails_io_sdk_version=0.13.8&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=LuvciVy", host: "v4.domain.com", referrer: "http://v4.domain.com/" 最近我已经在Ubuntu 16.04 VPS服务器上configuration了我的sails […]

如何限制/安全访问互联网上托pipe的开发人员的服务器

我为我的创业公司设置了两个Ubuntu虚拟专用服务器。 “公共”服务器(我们称之为www.example.com )应包含公开开放的公司网站和受限但相对较不敏感的服务,如LDAP和邮件服务器。 “dev”服务器( dev.example.com )将是该公司的Fort Knox持有公司的源代码(GIT),工件(Artifactory)和开发者工具(Atlassian)。 访问www.example.com应该对所有人开放,而开发服务器应该是非常安全的,只有非常有限数量的授权开发人员才能访问,其他公众理想情况下甚至不应该猜测服务器是否存在。 这两个服务器将托pipe在一个托pipe公司(我们有完全的根访问权限)。 我打算使用相同的域名和虚拟主机来设置Web访问。 example.com将指向“公共”服务器。 安装在“公共”服务器上的nginx将具有www.example.com虚拟主机(正常服务)和dev.example.com虚拟主机, dev.example.com主机的所有请求都将被代理到运行另一个nginx的“dev”服务器。 “dev”服务器上的防火墙将被设置为拒绝来自“公共”服务器的HTTPS和SSH呼叫以外的所有传入stream量。 因此,不仅可以直接连接到在“开发”服务器上运行开发人员工具的nginx服务器,而且还需要先login到公用服务器,以便能够通过SSH进入“开发”服务器。 因此,一个潜在的黑客无法直接访问“开发”服务器,而无需首先进入公共服务器。 如果重要的话,服务器可能会运行Ubuntu 16.04(我们可以select14.04,16.04,18.04和其他Linux版本,但Ubuntu 16.04对我来说听起来OK)。 我既不是安全专家,也不是系统pipe理员。 我有两个问题。 1)这听起来像是一个安全的设置,确认是“最好的实践”,还是有更好(更简单或更安全)的方法来实现相同的目标? 2) [主要问题] 。 如何限制HTTPS访问,以便只有开发人员才能访问dev.example.com,而其他用户即使猜对了URL也不会看到这个虚拟主机? 到目前为止,我有两个想法。 需要SSH隧道。 nginx中的“公共”服务器上的dev.example.com虚拟主机将被设置为只接受来自“公共”服务器的IP地址本身的请求,因此开发人员将不得不build立到“公共”服务器以访问dev.example.com 。 使用像MyEnTunnel(Window)这样的工具,可以很容易地设置SSH隧道,以便在启动时自动build立。 然而,我所看到的一个很大的缺点是,每个开发者都必须定义"dev.example.com"是指主机文件中的localhost (或者还有其他方法吗?) 客户端证书。 在“公共”服务器上的nginx基本上需要客户端证书才能访问dev.example.com 。 每个开发者除了拥有通常的login名和密码之外,还将拥有自己的客户端证书来访问dev.example.com,以便访问开发人员工具。 但是我对客户端证书不太熟悉,不了解所有的影响。 我看到的一个缺点是,当未经授权的人尝试访问dev.example.com他/她可能会得到一个“客户端证书”错误,这将显示开发服务器在那里,而第一种方法,他们将无法连接。 你会推荐我什么? 这个想法是保持简单,便宜,同时尽可能安全,直到公司发展到能承担系统pipe理员和自己的数据中心的程度。

缓慢的Nginx与基本身份validation

我有一个在Nginx服务SSL和基本身份validation背后的Web应用程序。 该应用程序很慢。 经过一番调查,我们注意到,删除基本authentication加快了速度。 我做了一些研究,发现实际的问题可能不是nginx,而是密码encryption方法。 在这个问答build议是使用简单的httpasswd作为一个解决密码的慢速authentication问题,但我使用它。 在服务器上的负载很低,有和没有基本的身份validation。 我能做些什么来查明问题? BTW。 我甚至尝试了简单的密码 – 这根本不起作用。

Nginx – 禁用http支持

我想我的服务器只响应https请求,我的SSLconfiguration工作正常。 我的问题是关于如何最好的禁用HTTP … 有一个默认的服务器端口监听端口80并返回一个444(见下面),或者完全删除所有端口80服务器模块会更好吗? 我会假设后者更好,因为它会导致服务器执行最小的处理量,但我无法find任何关于这个在线,所以也许我错过了什么? server { listen 80 default_server; return 444; }

Nginx与PHP子目录/ PHP部分处理

我有一个问题,我的nginx服务器。 安装: – Ubuntu 16.04.02 – Nginx 1.10.3 通过以下configuration我有以下结果: – ubuntulocal / =>工程 – ubuntulocal / mail =>工作 – ubuntulocal / dir2 =>返回php源代码 我现在试了很多,但没有find原因… server { charset utf-8; client_max_body_size 128M; listen 80; ## listen for ipv4 #listen [::]:80 default_server ipv6only=on; ## listen for ipv6 server_name ubuntulocal; set $root_path /var/www/html; root $root_path; index index.php; fastcgi_read_timeout 600; […]

用于同时反向代理和服务php文件的nginx服务器块configuration

我configuration了icecast2服务器,通过nginx反向代理,因为icecast完全不支持ssl。 我希望能够反向代理icecast提供的文件,并在同一时间内运行同一域名内的另一个位置的PHP。 例如proxiedicecast.org显示icecast服务的文件和proxiedicecast.org/status我可以服务其他内容。 我有默认的服务器块configuration,适用于icecast,但是当我尝试从“proxiedicecast.org/status”浏览器访问php文件只是下载PHP文件,而不是执行它们。 server { listen 80; server_name proxiedicecast.org; index index.php index.html index.htm index.nginx-debian.html; location ~ /.well-known { allow all; } location / { if ($ssl_protocol = "") { rewrite ^ https://$server_name$request_uri? permanent; } } # php location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } } […]

如何简化我的nginx反向代理configuration

我终于开始设置一个Nginx反向代理来处理我在我家的多个网站,因为我只有一个外部IP地址,一切正常,但是我想知道的是,如果有一种方法可以简化我的一个网站的当前configuration比我感觉需要的时间要长。 任何input,不胜感激。 server { listen 192.168.1.176:80; server_name ighfdexplorers.com; return 301 https://www.$server_name$request_uri; } server { listen 192.168.1.176:443 ssl http2; server_name ighfdexplorers.com; return 301 https://www.$server_name$request_uri; ssl_certificate /etc/nginx/ssl/ighfdexplorers/base/fullchain.pem; ssl_certificate_key /etc/nginx/ssl/ighfdexplorers/base/privkey.pem; } server { listen 192.168.1.176:80; server_name www.ighfdexplorers.com; return 301 https://$server_name$request_uri; } server { listen 192.168.1.176:443 ssl http2; server_name www.ighfdexplorers.com; set $upstream 192.168.1.179; ssl_certificate /etc/nginx/ssl/ighfdexplorers/fullchain.pem; ssl_certificate_key /etc/nginx/ssl/ighfdexplorers/privkey.pem; location / […]

Nginx在“?”url后面的子页面的位置

我试图把一个htpasswd只为这个url下的一组子页面: https://exemple.com/doku.php?id=staff 所以比如这个页面应该包括: https://exemple.com/doku.php?id=staff:modo 我试图在nginx中做到这一点: location ~ ^/doku.php?id=staff(.*) { auth_basic "Staff only"; auth_basic_user_file /etc/nginx/.htpasswd/.htpasswd-staff; } 但是,即使在主页面exemple.com/doku.php?id=staff上也没有任何操作 我也试过这个: location ~ ^/doku.php(.*) { if ( $query_string = "id=staff" ) { auth_basic "Staff only"; auth_basic_user_file /etc/nginx/.htpasswd/.htpasswd-staff; } } 但不能重新加载nginx的错误: nginx: [emerg] "auth_basic" directive is not allowed here in /etc/nginx/conf.d/site.conf:31 我错过了什么 ?

nginx +节点应用程序+ vuejs应用程序

我试图设置一个nginxconfiguration来尝试实现这一点: 我有一个nodejs应用程序,它在3000端口的本地主机上运行的服务器中服务于公共部分。 我有一个vuejs的水疗中心应用程序,服务应用程序的“pipe理”部分,在端口8000本地主机运行的服务器。 我想要实现的是,有一个nginx作为反向代理来代理所有请求到http://localhost:8080/和http://localhost:8080/*到nodejs应用程序和所有请求http://localhost:8080/admin到我的vuejs应用程序。 为此,我编写了一个像这样的nginxconfiguration文件: server { listen 8080; server_name localhost; location /admin/ { proxy_pass http://127.0.0.1:8000/admin/; proxy_redirect off; proxy_store off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; rewrite ^/admin/(.*)$ /$1 break; } location / { proxy_pass http://127.0.0.1:3000/; proxy_redirect off; proxy_store […]