Articles of nginx

nginx:未知的指令在configuration文件中用Dokku静态部署拒绝

我得到一个“未知的指令”错误deny在我的nginx confg。 错误: nginx: [emerg] unknown directive "deny" in /app/nginx/nginx.conf:22 configuration: worker_processes 1; error_log stderr; pid nginx.pid; daemon off; events { worker_connections 768; } http { types_hash_max_size 2048; include mime.types; server { listen {{ $.PORT }}; server_name _; {{ if ne $.NGINX_ROOT "" }} root /app/www/{{ $.NGINX_ROOT }}; {{ else }} root /app/www; {{ end […]

Nginx:提供不同根目录下的magento站点以及其他magento根目录下的子目录

经过数小时的search和testing,我还没有得到这个工作。 我在/ srv / site1 / htdocs有一个正在运行的magento安装。 我在/ srv / site2 / htdocs有另一个magento安装。 我需要site2加载在site1.com/site2/。 棘手的权利? 到目前为止,我已经有site1.com/site2加载了一个无风格的404页面,用于site2 magento安装,这个目录里面的所有内容都会抛出一个404.下面是我的整个nginx conf: server { listen 80; server_name site1.com; root /srv/site1.com/htdocs; index index.php; client_max_body_size 500M; location ~ /site2 { root /srv/site2/htdocs; add_header Access-Control-Allow-Origin "*"; index index.php index.html; try_files $uri $uri/ /index.php?$args; expires 30d; location ~* \.php$ { try_files $uri =404; […]

nginx httpredirect到https无限循环

我有我的configuration文件。 这是一个旧的。 server { listen 80; server_name .lala.mana.lan; access_log /var/log/nginx/lala.access.log; error_log /var/log/nginx/lala.error.log; proxy_conect_timeout 600; proxy_send_timeout 600; proxy_read_timeout 600; send_timeout 600; location / { proxy_pass http://lala proxy_next_upstream error timeout invalid_header http_500 http_502 http_503; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; proxy_redirect off; } location ~* /web/static/{ proxy_cache_valid 200 60m; proxy_buffering on; proxy_pass http://lala; } […]

nginx作为WebSocket的代理:检查并阻止某些请求

我将NodeJS作为一种服务于AngularJS前端的Web应用程序服务器来运行。 他们仅通过WebSockets进行通信,使用Socket.IO的SailsJS实现。 在前端(客户端)和NodeJS后端之间,nginx作为代理,像这样configuration: server { listen 1337 ssl; location /socket.io/ { proxy_pass https://localhost:1338; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_http_version 1.1; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 到现在为止还挺好。 我现在想要监视和保护WebSocket连接。 特别是,我想防止XSS攻击,并排除试图暴力login到我的应用程序的IP。 我很新的东西,但经过一些研究,我遇到了fail2ban和nginx-naxsi这可能正是我所需要的。 但是,我不知道如何使他们与我的设置工作。 这甚至有可能吗? 我可以以某种方式拦截通过在代理中的WebSocket(是Nginx)隧道通信?

反向代理HTTP到TCP

我们有一个在TCP套接字上侦听非HTTP请求的服务。 我们希望在它之前放置一个HTTP反向代理,使HTTP请求的主体作为整个请求被转发到TCP套接字。 我们已经看过用nginx做这个,但是它可以很容易地反向代理TCP -> TCP和HTTP -> HTTP ,但是我们还没有find任何方式来做HTTP -> TCP 。 是否有任何“开箱即用”的反向代理软件能够为我们做到这一点,还是我们需要build立一些自定义?

NGINX不能访问html文件和下载php文件

一切工作正常,但我做了很多修改,然后我只能得到一个空白页。 这是一个新的NGINX安装,所以我决定删除/etc/nginx文件并重新安装。 apt-get purge nginx nginx-common nginx-full apt-get install nginx nginx-common nginx-full 现在PHP文件不会加载,奇怪的是我无法访问文档根目录(/ usr / share / nginx / html)中的文件“test.html”。 nginx版本:nginx / 1.10.3 cat /etc/nginx/sites-available/default server { listen 88 default_server; root /usr/share/nginx/html; index index.php index.html; access_log /var/log/nginx/default-access_log; error_log /var/log/nginx/default-error_log; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { #try_files $uri =404; fastcgi_index […]

Nginx的Docker 400错误的请求

我目前正在尝试将nexus作为我的组织内的泊坞窗图像的私人registry。 我的nginxconfiguration如下。 user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr – $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; server { listen 6666; ### Docker Hosted Repo […]

net :: ERR_CONTENT_LENGTH_MISMATCH在Nginx和SSL上

我遇到了一个我无法解决的服务器问题。 我一直在Chrome浏览器中获取net :: ERR_CONTENT_LENGTH_MISMATCH或css / js脚本。 Nginx不是代理,它只是自己提供文件。 错误不会每次都出现,而且在我刷新页面后,它就会消失。 它出现在计算机与服务器的快速互联网连接(testing多个networking)。 它也出现在Firefox中,但有一个不同的错误信息。 Iv'e试图禁用服务器上的gzip,禁用文件metdatacaching,没有任何工作。 过了一段时间,我发现这个错误只出现在https上,而不是http。 所以我试图改变SSL密码,将SSL证书从Letsencrypt更改为Comodore,没有任何工作。 我已经更新了nginx,仍然是同样的问题。 user nginx; worker_processes 12; error_log /var/log/nginx/error.log crit; pid /var/run/nginx.pid; events { worker_connections 20000; #use epoll; multi_accept on; } http { include /etc/nginx/mime.types; default_type application/octet-stream; #open_file_cache max=200000 inactive=20s; #open_file_cache_valid 30s; #open_file_cache_min_uses 2; #open_file_cache_errors off; open_file_cache off; log_format main '$remote_addr – $remote_user [$time_local] […]

Nginx的日志根据大小旋转

我正在使用下面的cfg日志旋转的大小,但它不工作。 /var/log/nginx/access_log { rotate 7 size 5k dateext dateformat -%Y-%m-%d missingok compress sharedscripts postrotate test -r /var/run/nginx.pid && kill -USR1 `cat /var/run/nginx.pid` endscript } 更新1: user nginx; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr – $remote_user […]

Nginx的限制例外

我已经在我的Nginxconfiguration中成功应用了1r / s的速率限制,但是我想实现一个function,将白名单IP地址应用不同的速率限制设置(20r / s)。 这里是相关的configuration设置: nginx.conf limit_req_zone $limit zone=all:20m rate=1r/s; domain.conf geo $whitelist { default 1; 1.1.1.1 0; } map $whitelist $limit { 0 ""; 1 $binary_remote_addr; } limit_req zone=all burst=5; 这个按预期工作,当我列入白名单1.1.1.1时,我完全可以不受限制地访问网站。 我如何才能为白名单IP实现20r / s的限制? 我知道解决scheme不是使用2个区域,但是我已经多次阅读文档,并且对如何实现这一点感到茫然。 提前致谢。