Articles of nginx

如何创build用户“nginx”?

我只是从源安装nginx 但是当运行/etc/init.d/php_cgi start ,会有一条消息: Starting php-cgi: spawn-fcgi: can't find user name nginx …我不知道他们的许可。 以前我用yum (CentOS)安装nginx,

Nginx SSL无法正常工作

我正在用nginx运行一个debian压缩web服务器,并且我无法使SSL工作。 我得到的错误不是从apache,而是从客户端Web浏览器,与“连接超时错误” 我已经从StartSSL购买了一个SSL证书,如果没有,我尝试生成我自己的只是为了排除故障。 两个都产生了相同的错误,都没有工作,我的nginx日志没有显示任何东西。 我的SSLconfiguration看起来像这样: server { listen 443 default_server ssl; server_name tarror.org www.tarror.org; ssl on; ssl_certificate /srv/ssl/nginx.pem; ssl_certificate_key /srv/ssl/nginx.key; root /wdata/tarror.org; index index.php index.htm index.html; location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /wdata/tarror.org$fastcgi_script_name; include fastcgi_params; } }

根据nginx中的MIMEtypes有条件添加expires标头

在Ubuntu 12.10上运行nginx 1.4.1 需要有条件地发送过期标题,并基于http响应的MIMEtypes/内容types。 在位置内添加了这段简单的代码/ { if ($sent_http_content_type = "text/css") { expires 7d; } 即使$ sent_http_content_type包含“text / css”,也不会发送expires头文件 如何解决这个问题? 检查文件扩展名是不够的,因为在我的应用程序js,css中,图像是从PHPdynamic生成的。 所以需要检查MIME并添加标题。

Nginx:将IP地址redirect到域名

使用以下Nginxconfiguration: server { listen 80; listen [::]:80 default_server ipv6only=on; server_name isitmaintained.com; … } server { listen 178.62.136.230:80; server_name 178.62.136.230; add_header X-Frame-Options "SAMEORIGIN"; return 301 $scheme://isitmaintained.com$request_uri; } 我试图redirecthttp://178.62.136.230/到http://isitmaintained.com/但是当我部署这个configuration我结束了一个Redirect loop或这两个链接。 我究竟做错了什么?

在Nginx中的位置服务多个代理端点

我有几个API端点,我想在一个单独的/api位置下进行服务,子path到达不同的端点。 具体来说,我希望webdis在/api和/api/mypath提供的专有API可用。 我并不担心与webdis API发生冲突,因为我使用的子path不太可能与redis命令名冲突,而且也完全控制了API的devise以避免冲突。 这里是我一直在testing的我的testing服务器的configuration文件: server { listen 80; server_name localhost; server_name 192.168.3.90; server_name 127.0.0.1; location / { root /home/me/src/phoenix/ui; index index.html; } # temporary hardcoded workaround location = /api/mypath/about { proxy_pass http://localhost:3936/v1/about; } location /api { rewrite ^/api/(.*)$ /$1 break; proxy_pass http://localhost:7379/; } # tried this but it gives "not found" error #location ^~ […]

在nginx中将http://example.com:12345redirect到https://example.com:12345

我知道这一定是已经回答了,但是我一直在寻找一段时间,找不到答案。 只是不在正确的地方,我想,也许有人可以帮助我。 基本上我通过SSL在非标准端口上运行phpmyadmin,在这个例子中是12345。 现在我有https://example.com:12345设置好了,它的工作原理和一切。 现在我想添加inputhttp://example.com:12345并redirect到https://的function。 我假设以下将工作,但事实并非如此。 server { listen 12345; server_name php.myadmin.com; if ( $scheme = http ) { rewrite ^ https://php.myadmin.com:12345$request_uri? redirect; } root /var/www/php; ssl on; [….] } 这给了我一个400 bad request 。 现在,在发布答案之前,请务必仔细阅读redirect表单。 检查链接下面的陷阱。 https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites 此外,如果甚至可以在没有if语句的情况下完成这将是很好的: https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#using-if

Nginx:使用头检测HTTPS连接

在我的负载均衡器上,我终止与Nginx的HTTPS连接,然后将请求代理到一个也由Nginx支持的Web服务器。 在fastcgi_params的负载均衡器中,我有: fastcgi_param HTTPS $https; 在Web服务器上有一个只能通过HTTPS访问的站点。 如何检测HTTPS参数是否设置,如果不redirect到网站的安全版本?

nginx – 在更新时提供陈旧的caching响应

在nginx中我使用的是 proxy_cache_use_stale updating 指令( http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_use_stale ),以便对失效的caching内容的并发请求仅向上游发送1个请求(非首先请求用陈旧内容响应第一个请求是更新内容)。 这工作得很好。 现在有没有办法让第一个请求立即响应陈旧的内容,同时触发更新? 现在,对于非首先失效的请求,响应时间非常好,但是第一个需要等到后端响应。 我更喜欢在caching更新之前提供陈旧的内容。

我不小心删除了/ etc / nginx,重装nginx不会恢复它

我在Ubuntu上,当我不小心删除整个文件夹时,我试图恢复/etc/nginx/sites-enabled/default的原始设置。 通过apt-get卸载并重新安装nginx将不会重新创build原始文件夹。 我能做些什么来恢复他们?

如何configurationnginxredirect从域别名到主域的所有请求?

我有一个nginx服务器响应几个域,我想redirect到主域的所有请求。 例如: xxx xxx.example.com yyy.example.com $hostname网站响应xxx xxx.example.com yyy.example.com $hostname用于http和https 。 我想configuration服务器的方式,所有对其他域名的请求将redirect到xxx.example.com 。