Articles of nginx

nginx的尝​​试文件子目录不工作

我有configuration文件,我使用根目录超出public_html,因为我想分开静态文件和PHP。 root /home/user/domain; location / { try_files /static/$uri /static/$uri/ /php/index.php?$args; } location ~ \.php$ { fastcgi_pass hiphop; include /etc/nginx/fastcgi.conf; try_files /static/$uri /static/$uri/ /php/index.php?$args; } 我错在哪里?

NGINX端口代理不工作

我试图做到这一点,而不是键入“www.example.com:8080”,我只是键入“www.example.com”。 我正在使用NGINX,但我似乎无法得到它的工作。 我在网上发现了许多有用的文章,他们都说要做同样的事情,我已经尝试过,但不起作用。 我在一个Ubuntu的Apache2服务器上运行 在这里我做了什么: Sudo进入位于/ etc / nginx / site-enabled / default的configuration文件 听80的地方,把它改为听8080 sudo服务nginx重启 但是,这似乎没有效果。 默认 # You may add here your # server { # listen 80; # server_name graychat.net; # location / { # proxy_pass http://127.0.0.1:8080; # } # } # statements for each of your virtual hosts to this file ## […]

将httpsredirect到http后redirect错误

我已将所有https请求redirect到http。 在这里你可以看到我在nginxconfiguration文件中做了什么: * #redirecting https to http:: server { listen 443 ssl; listen [::]:443 ssl; server_name example.com www.example.com ssl_certificate /etc/nginx/sd.crt; ssl_certificate_key /etc/nginx/sd.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; rewrite ^(.*) http://www.example.com$1 permanent; } #redirecting non-www to www:: server { listen 80; listen [::]:80; server_name example.com; return 301 http://www.example.com$request_uri; } #server block server { listen 80; […]

通过URL访问服务器文件系统

我有一个ec2实例。 自启动以来,我可以通过公共DNS(在浏览器中)访问实例。 我最初设置实例,因为我需要一个PHP脚本,我的应用程序连接。 最近,我在盒子上托pipe了另一个应用程序,但希望应用程序(监听端口8080上的节点应用程序)可以通过我购买的域进行访问,因此我将实例与弹性IP相关联,然后将其连接到我的域。 然后我使用nginx将请求转发到我的应用正在监听的端口8080。 一切都很好。 现在,问题是,我不能再通过原始URL(publicdns / somefolder / file.php)访问我的PHP脚本。 我最初的想法是,这是预料之中,所以我尝试elasticip / somefolder / file.php。 仍然没有运气。 我如何在浏览器中访问这个脚本?

nginx:String用连字符replace加号

我正在尝试重写数百个url,除了一个场景外,我已经非常接近了。 有些url是这样的: /city/?sl_city=CityName&directory_nonce=45ad967e02 但是有些在sl_city查询sl_city有一个+作为单词分隔符。 那些需要改变为- /city/?sl_city=Some+City&directory_nonce=45ad967e02 这两个url的最终结果应如下所示: /locations/cityname /locations/some-city 我的基本重写规则是这样的: location ~* ^/city/(.+)? { if ($args ~* "sl_city=(.+)&directory_nonce=(.+)") { set $city $1; set $args ''; rewrite ^.*$ /locations/$city permanent; } } 但我的第二个URL 404s(回来/locations/Some+City ),但locations/Some-City解决。 目前我并不担心这些URL。 基本上我想检查$city之前,它做了最后的永久重写,任何+find,将其更改为- 。 我所看到的所有例子都涉及安装另一个模块,我认为我不能这样做。 而我迄今为止的尝试没有奏效。 编辑 这是我安装的模块。 试图找出是否ngx_http_substitutions_filter_module做我所需要的,但不知道。 nginx version: nginx/1.8.0 built with OpenSSL 1.0.1f 6 Jan 2014 TLS SNI support […]

Nginx的:可能在位置块dynamicparsingDNS?

目前我正在用Kubernetes使用Nginx。 在我的Nginx conf文件中,我有以下代理传递: location ~ /myPath/([\w-]+)/resources { rewrite ^/myPath/([\w-]+)/resources/(.*)$ /myNewPath/$1/resources/$2 break; proxy_pass http://$1; } 目前Nginx抱怨说,在运行时无法parsing$ 1来执行proxy_pass(尽pipe我们有我们的SkyDNSparsing器指定,即parsing器10.250.0.5有效= 5秒)。 我们需要dynamic地完成这个工作,因为在Nginx启动时,$ 1的值可能不知道,必须在请求时解决。 Nginx是否能够dynamic地做这个dynamic的DNSparsing?

使用Letsencrypt启用SSL后,Drupal 7login无法在NGINX上运行

我遵循优秀的数字海洋教程和SSL证书validation有效。 然而,访问pipe理员的Drupallogin不再激活,页面只是重新加载到自己。 我启用了NGINX日志的debugging,下面是结果。 它结束于:* recv()未准备好(11:资源暂时不可用)。 * 奇怪的是我们的开发Drupal网站工作得很好。 当我比较这些日志时,唯一的区别是它出现在dev站点中: 4 http请求行:“POST / user HTTP / 1.1” 以下是详细的debugging日志。 有什么build议么? 下面是curl -vvv到login页面的结果。 另外nginx / 1.4.6(Ubuntu) 2016/01/21 11:38:56 [debug] 12534#0:* 6467 write new buf t:1 f:0 00000000025F8510,pos 00000000025F8510,size:239 file:0,size:0 2016/01/21 11:38:56 [debug] 12534#0:* 6467 http写入filter:l:0 f:0 s:239 2016/01/21 11:38:56 [debug] 12534#0:* 6467 http output filter“/ node / add / […]

如何在保留静态资源的相关URL的同时设置NGINX反向代理?

我试图在NGINX中使用proxy_pass设置一个反向代理。 页面加载正常,但所有使用相对URL的静态辅助(js,css,imgs)都会因为它预先安装父服务器的主机名而中断。 有没有办法使用反向代理,同时维护所有静态资源的代理主机名? parent.conf server { listen 80; server_name parent.mydomain.com; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name parent.mydomain.com; root /var/www/parent; index index.html; try_files $uri.html $uri $uri/ =404; # error and access out error_log /var/log/error.log; access_log /var/log/access.log; ssl on; ssl_certificate /etc/ssl/myssl.pem; ssl_certificate_key /etc/ssl/myssl-key.pem; # Here is the important part. Any url matching # […]

Nginx反向代理只适用于登陆页面,任何其他的链接将无法正常工作

我有一个反向代理/forums设置像这样: server { listen 80; server_name localhost; location / { proxy_pass http://127.0.0.1:3000; 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; } location /forums { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:4567/; proxy_redirect off; # Sockect.IO Support proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection […]

如何使httpredirect工作无redirect循环

我有以下nginx conf文件,我想要的一切工作除了httpredirect到https的stream量。 当我将server_name example.com添加到将httpredirect到https的(第一个)服务器块时,浏览器中出现redirect循环错误。 我究竟做错了什么。 如何在不redirect循环的情况下将httpstream量redirect到https,同时保留wwwredirect到根域 server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; rewrite ^(.*) https://example.com$1 permanent; } server { server_name www.example.com; rewrite ^(.*) https://example.com$1 permanent; } server { server_name example.com; root /usr/share/nginx/html; index index.php index.html index.htm; ssl_certificate /root/cert_chain.crt; ssl_certificate_key /root/example.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { […]