Articles of nginx

使用Nginx作为子目录托pipe一个WordPress博客

我有一个现有的meteor应用程序,并使用nginx作为我的服务器,可以在example.com上说 我想添加一个WordPress的博客,应该访问example.com/blog 我最好还是希望我的博客存在于自己的小滴(服务器)上,但是如果它需要在同一个小滴(服务器)上,那就没问题。 我该怎么做呢? 我已经能够在blog.example.com上使用不同server_name的不同服务器块。 我也得到了静态文件,可以在example.com/blog/index.html的子目录下访问。 这一切都存在于同一滴(服务器)上 。 但是我无法通过example.com/blog访问wordpress应用程序。 编辑: 我最终做的是创build一个新的服务器实例(滴),configuration它与LEMP堆栈和NGINX。 如果我尝试访问IP,它将起作用。 现在,在我的实际服务器上,添加了一个位置块 location /blog { rewrite ^/blog/(.*)$ /$1 break; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_pass http://wordpress-server-ip; proxy_redirect off; } 我的新问题是,我的博客无法加载.css文件在铬合,因为我的代理服务器configuration为HTTPS和WordPress通过HTTP加载文件。 你可以在https://juerix.com/blog查看。 所以我进入了我的wp-config文件,并改变了网站和WordPress的urlhttps://juerix.com/blog 。 没有帮助。

Nginx:如何将所有请求从https://domainA.comredirect到https://domainB.com? (而不只是http的)

我有几个域名,我想redirect到https://indi-ticket.fr 我configuration了Nginx, http ://other-domain.xx中的所有请求都被redirect到了htpps://indi-ticket.fr,但不是来自https ://other-domain.xx的这些请求。 这是我的Nginx conf的相关部分: server { listen 80; server_name www.indi-ticket.fr indi-ticket.fr www.indi-tickets.fr indi-tickets.fr www.indi-ticket.com indi-ticket.com; return 301 https://indi-ticket.fr$request_uri; } server { listen 443 ssl; server_name indi-ticket.fr; ssl on; … 这个conf有什么问题? 什么curl -I -L https://indi-tickets.fr不redirect到https://indi-ticket.fr ?

Nginx过期似乎是错误的

我刚刚重新安装我的机器,以删除旧的依赖关系,并以一种更合适的方式安装的东西,我刚刚意识到caching似乎错了。 标题如下图所示: cache-control:max-age=300 content-type:image/png date:Wed, 09 Nov 2016 13:17:50 GMT expires:Wed, 09 Nov 2016 13:22:50 GMT last-modified:Wed, 09 Nov 2016 12:25:44 GMT server:nginx/1.11.5 status:200 你可能会看到到期的是5m 。 但是,高速caching块设置为: location /assets { alias /var/www/f13/content/themes/lechuck/assets; access_log off; expires max; } 所以它应该是10年。 这是整个文件: # sets the proxy cache path location, max size 2g proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=STATIC:100m inactive=24h max_size=2g; […]

Nginx将所有位置块redirect到除1之外的https

我有一个nginxconfiguration,一切都强制为https。 我想添加一个位置块通过http服务。 我得到一个“太多redirect”与我目前的configuration。 这是configuration # HTTP server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; server_name example.com; # redirect non-SSL to SSL location / { return 301 https://$server_name$request_uri; } location /blog { rewrite ^/blog/(.*)$ /$1 break; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_pass http://remote-ip; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } #HTTPS server server{ […]

Nginx拒绝所有的位置块没有按预期工作

我有一个与Nginx的WordPress的博客设置。 我一直看这个 80.82.64.220 – – [10/Nov/2016:08:21:48 +0000] "POST /xmlrpc.php HTTP/1.0" 499 0 "-" "Mozilla/4.0 (compatible: MSIE 7.0; Windows NT 6.0)" 这是每秒一个请求。 所以我试图通过nginx的conf文件拒绝访问xmlrpc.php。 location /xmlrpc.php { deny all; access_log off; } 我尾巴的访问文件,可以看到它仍然被访问。 不知道为什么。 我尝试从我的开发机器curl随机参数,我得到一个XML文件。 我不知道为什么我得到一个XML文件。 我注意到所有请求都来自同一台服务器。 所以我想我们只是阻止IP,所以我做 sudo ufw deny from 80.82.64.220 我检查状态,它确实显示规则被添加。 我尾巴的访问文件,我仍然可以看到该文件正在访问。 防火墙和nginxconfiguration文件(包括访问日志文件)的所有更改都在我的实际服务器上。 这个服务器位于一个nginx反向代理的后面。 反向代理的访问日志没有这个访问日志,所以我猜测,主服务器正在被直接访问。 但是,文件仍然被访问?

从nginx中重写执行排除文件夹

我有一个情况,我有domain.com以及一个单独的代码m.domain.com。 所以我检查用户是否从移动重写到m.domain.com否则访问常规domain.com,但我有一个文件夹domain.com/blog不应该redirect到m.domain.com,即使用户是从移动。 我尝试了所有'嵌套'的可能性,但失去了一些东西。 这是我所尝试过的。 任何帮助深表感谢 我的nginx.conf server { listen 80; server_name domain.com; rewrite ^(.*) http://www.domain.com$1 permanent; } server { listen 80; server_name www.domain.com; set $mobile_rewrite do_not_perform; if ($request_uri !~ "^/blog/\w+$") { set $mobile_rewrite do_not_perform; } if ($http_user_agent ~* "(android|bb\d+|meego).+mobile||iemobile|ip(hone|od)||up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") { set $mobile_rewrite perform; } if ($mobile_rewrite = perform) { rewrite ^ http://m.domain.com$request_uri? redirect; break; […]

将所有stream量redirect到除一个URL之外的HTTP

我一直在挠头,因为所有的论坛都说,以下简单的代码应该工作,redirect所有stream量从HTTPS到HTTP,除了一个位置( Nginx的:在一个path上强制SSL,其他人不SSL ),但在我的情况它没有按预期工作 这是Magento网站有以下nginxconfiguration upstream examplecombackend { server unix:/var/run/php-fcgi-examplecom.sock; } server { listen 111.11.111.111:80; server_name example.com *.example.com; access_log /home/www/vhosts/example.com/logs/access.log; error_log /home/www/vhosts/example.com/logs/error.log; root /home/www/vhosts/example.com/httpdocs; location / { index index.html index.php; try_files $uri $uri/ @handler; expires 30d; } location /checkout/ { rewrite ^ https://$host$request_uri? permanent; } location @handler { rewrite / /index.php; } location ~ .php/ { […]

nginx基于位置和邮件标题的速率限制

Nginx有这个有用的模块,名为ngx_http_limit_req_module ,您可以根据IP或请求数量限制对服务器的请求。 是否可以限制包含自定义标题的位置? 例如,我尝试过,但它无法启动nginx。 location /myservice { if ($http_x_custom_header) { limit_req zone=one burst=5; } } 具体的错误是: nginx:[emerg]“limit_req”指令不允许在/ etc / nginx / sites-enabled / default这里 即它不喜欢if块中的limi_req指令。 在if区块之外很好。 尽pipe如此,我也许能够在位置之外使用不同的极限参数。

从nginx / iptables中拒绝X-Forwarded-For IP

下面是以下内容 visitor –> Cloudflare proxy –> Front –> Back ^^^^^^ –>iptables(fail2ban)–>nginx–> 我想要做的是通过401拒绝追踪bruteforcing IP,并禁止这个IP做任何后续的请求。 FE BE | | .. | | | POST /oauth/token | |——————–>| | 401 (access denied) | |<——————–| .. | | | | 但是,FE上唯一的入站地址是cloudflare的IP,而不是访问者的IP。 因此,我不能通过iptable禁止传入的IP。 我只看到两种方式: configurationnginx使用X-Forwarded-For(或通过cloudflare给出的CF-Connecting-IP addionnally),加上评估401响应加上limit_req(这是否可行?怎么办? 而不是通过fail2ban监测检测到的bruteforcingIP,将其映射到禁止的ip(例如140.1.1.1或非洲的任何IP),并通过nginx上的Deny指令拒绝httpstream量。 其中一个可行的是? 如果不是,可以select吗?

Nginx的SSLconfiguration不工作,为什么?

我有在Windows Server 2012 R2上运行的nginx 1.10.1 ,并且我刚从GoDaddy购买并安装了一个SSL证书。 我改变了我的configuration,我认为应该是,但它不工作。 该网站仍然在http工作,但我得到超过https的超时。 我希望这是一个很简单的东西,我错过了。 这是我第一次尝试用nginx安装SSL证书。 nginx.conf worker_processes 1; events { worker_connections 1024; } http { server_tokens off; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; # http://stackoverflow.com/questions/12640014/enable-gzip-for-css-and-js-files-on-nginx-server-for-magento gzip on; gzip_comp_level 6; gzip_min_length 1100; gzip_buffers 16 8k; gzip_proxied any; gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml image/x-icon […]