Articles of nginx

如何在此nginxconfiguration中closures只有特定url的访问日志?

这是一个nginxconfiguration server { listen $PORT; location ~ ^/documents/(.*)$ { proxy_pass http://127.0.0.1:5000/$1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location = /favicon.ico { return 204; access_log off; log_not_found off; } } 有两种使用情况的url /documents/ : POST到/documents/进行一些处理或 AWS ELB使用GET /documents/ping作为运行状况检查 在cloudwatch日志中,我得到了一堆ping条目 问nginx不loggingping的最简单方法是什么?

用HTTP / 2启用gzip_static值得吗?

在一个静态的网站上,我将页面预压缩到最大压缩级别的.gz文件,并使用gzip_static on; 。 我也有HTTP / 2启用。 我的问题是这些事情是否一起顺利,因为我在日志中主要看到HTTP / 1.1请求。

防止nginx访问日志填满静态请求

对我的/static/文件夹中的favicon.ico和资产的无用GET请求正在抛弃我的nginx访问日志。 这是一个繁忙的服务器 – 意味着I / O也被浪费了。 更何况我的fail2ban安装有时需要扭曲的决定! 我如何排除这些令人讨厌的日志行? 我在nginx 1.4.x 。 我find了一种方法来做到这一点,而不是在nginx。 这是我的nginx虚拟主机文件: proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=100m inactive=6m; upstream my_server { server unix:/home/myuser/myfolder/myapp/myapp.sock fail_timeout=0; } server { server_name example.com www.example.com; listen 80; return 301 https://example.com$request_uri; } server { server_name www.example.com; listen 443 ssl; listen [::]:443 ssl; . . . SSL related stuff . . […]

如何在nginx中查询query_string参数?

如何在nginxconfigurationtesting中写入一个条件,如果在URL中input了q参数? 这不起作用: if ($arg_q) { return 301 "/someurl"; } 它捕获的URL像 /search?entered_search=1&q=123 但是它不会捕捉到类似的URL /search?entered_search=1&q=

即使netstat说Nginx会这样做,Nginx也不会听443

我在服务器上安装了SSL,一切顺利,就像我以前在其他服务器上做的那样,但是这只是不起作用,我用sudo netstat -t -l -p -n来检查 ,我得到这个: Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1062/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2560/exim tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 3129/nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3129/nginx 但是,当我尝试访问该网站,连接超时,现在如果我检查https://www.yougetsignal.com/tools/open-ports/端口443,它会说该端口已closures。 Nginx -t没有返回错误。 sudo iptables -L显示: Chain INPUT (policy ACCEPT) […]

在使用相同html页面的不同url上使用sub_filter

我试图绕开SPA(即JavaScript呈现的页面)不能提供twitter元数据和元数据必须是服务器html页面的一部分的事实。 有许多适当的解决scheme,像服务器端渲染这个问题,但我正在寻找一个更快的方式,因为我想这只是由3个不同的网站服务的页面。 我想要达到的是: http://example.com =>通常服务于index.html(index.html具有硬编码的元标题标签) http://example.com/accept服务于index.html,但通过sub_filter的用法代替meta标签,在那里接受单词accept http://example.com/reject提供index.html,但通过使用sub_filterreplacemeta标签,在那里有拒绝 我尝试使用不同的位置,如: location / { try_files $uri /index.html; } location /accept { sub_filter 'normal' 'accept'; sub_filter_once off; try_files $uri /index.html; } 但我得到了正常的meta标签index.html。 如果我移动/位置的sub_filter然后stringreplace工程虽然。 还尝试重写,如果内部位置等,但无法得到它的工作。

nginx服务器上的指向index.html的奇怪的redirect问题

我正在尝试使用nginx部署单页面应用程序,这里是下面的configuration。 server { listen 24670 default_server; listen [::]:24670 default_server; server_name *******; root /home/gerry/client/dist; index index.html index.htm; location / { try_files $uri /index.html; } } 每当我尝试访问该页面,我会得到一个500内部服务器错误,并在检查日志,我会看到以下错误。 2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: Permission denied), client: 183.83.241.76, server: app.url.com, request: "GET / HTTP/1.1", host: "app.url.com:24670" 2017/10/15 18:20:17 [crit] 8752#8752: *2 stat() "/home/gerry/client/dist/index.html" failed (13: […]

优雅的networking应用程序重新加载

我有一个通过Gunicorn运行的WSGI Python应用程序: CONFIG = { 'bind': "unix:{}".format(os.path.join(RUN_DIR, "brain.sock")), 'preload_app': False, # supervisord requires that the child process runs in foreground 'daemon': False, … } 它通过Nginx的套接字文件接收HTTP请求: server { … location / { proxy_pass http://unix:$root/run/brain.sock:; … } Gunicorn通过Supervisord运行: [program:myapp] command = venv/bin/gunicorn -c gunicorn.conf.py myapp.wsgi:application … 我正在考虑一种无需停机和等待时间来部署我的应用程序的方法。 每个工作人员最多可能需要30秒才能填满caching。 我的想法是这样部署的: 用新的代码启动第二个Gunicorn,它将监听另一个套接字文件。 等到应用程序开始,所有的caching被填满。 重命名套接字文件以指向Nginx使用的位置。 Nginx仍然会将请求发送到旧套接字。 用旧的应用程序版本closures老Gunicorn。 Nginx将会看到socket被closures,并且会从同一个地方重新打开一个新的socket。 这会工作吗? 我是否重新发明了轮子?

nginx – bind()到0.0.0.0:80失败(98:地址已经在使用中)

我有一个反向代理5服务器configuration设置,但是,自从开始,它总是抱怨不能监听我指定的端口,所以服务器无法启动。 我已经尝试了几件事情: 将sites-availableconfiguration分割为多个文件sites-available并创build符号链接以sites-enabled 删除listen属性,并允许它回退到默认值 将端口更改为ipv6only=on – 导致错误 将端口更改为[::]:80 改变港口,以便没有冲突,即81等 使用netstat我可以看到,没有什么是我需要的端口上运行,当我运行nginx -t我得到一个成功的输出说句法是好的,nginx.conftesting成功。 这是我的nginx输出: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:81 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:82 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:83 failed (98: Address already in […]

Nginx子目录 – 位置path添加到根

在我的主webroot的子目录中访问wordpress安装。 我的主要网站存储在/var/www/example.com/htdocs 我的wordpress安装存储在/var/www/wordpress.example.com/wordpress 我希望能够从example.com/blog访问我的wordpress安装 server { … root /var/www/example.com/htdocs; … location ^~ /blog { root /var/www/wordpress.example.com/wordpress; } } 但是,我得到一个404 /blog被添加到根(也是不希望的)。 找不到“/var/www/wordpress.example.com/wordpress/blog/index.php” 注意root如何显示/wordpress和/blog 。 我的愿望只是为了显示/wordpress 。 我希望它可以从/blog访问,但/blog不应该是根部分,因为它不存在。 你能帮我解决吗?