Articles of nginx

我可以在只有一个IP的同一台服务器上运行Apache2和Nginx吗?

我最近build立了一个Ubuntu 12服务器(在Rackspace Cloud的下一代服务器上)。 我将在这台服务器上提供10个小型networking应用程序。 由于这些应用程序是如何构build的,PHP应用程序需要在Apache上运行,并且Rails应用程序需要在Nginx上运行。 Rackspace将不允许单个服务器上的多个IP。 是否可以在同一台服务器上使用同一个IP地址在端口80上运行apache2和nginx? 我发现的唯一信息涉及使用nginx代理请求到apache域的apache。 我发现的代理信息只能提到nginx直接提供的静态页面服务器。 我如何设置我的Ubuntu服务器在同一台服务器上运行apache2和nginx只有一个IP地址?

显示404未find的子域,而不是显示根域的内容

我正在使用nginx。 我正在努力实现的是: 从/var/www/domain.com获取内容的根域domain.com 从/var/www/sub.domain.com获取内容的子域sub.domain.com 任何其他子域*.domain.com (其中* != sub )应从/var/www/404获取内容 如果这不清楚:它类似于StackEchange设置,其中http://somesub.stackexchange.com/提供了一个404。 我在第一次使用两个不同server_name的服务器块成功。 但是,如果没有find匹配子域的服务器块,如何设置nginx链接到/var/www/404 ? 使用基本设置,所有未find的子域将返回与根域相同的内容。 我想使这个通用的,所以,如果我添加另一个服务器块sub2.domain.com ,我不必改变404的块。 我现在使用的代码是: server { listen 80; server_name domain.com; root /var/www/domain.com; charset utf-8; location / { index index.php index.html; autoindex on; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } server { listen 80; […]

如何告诉php-fpm发送php错误日志到nginx错误日志?

当我使用apache / mod_php时,PHP错误将出现在apache的错误日志中。 现在,我用nginx通过fcgi使用php-fpm,是否有可能在nginx错误日志中也有PHP错误日志? 到目前为止,唯一的解决scheme是使用php.ini中定义的外部文件 error_log = /tmp/php_errors.log 但是我希望他们在nginx错误日志中易于维护。

https www无法redirect到非https的https nginx

我似乎无法将我的https://wwwredirect到https://当前该网站如何认为www 。 是一个完全独立的网站。 我想正确的redirect,但是当我在我认为正确的地方添加configuration时,我得到了一个无限的redirect。 非https wwwredirect正确。 唯一的问题是https://www 。 这里是我的nginxconfiguration,也许我只是想念一些东西。 我删除了https://wwwredirect,因为我似乎无法正确地进行。 server { listen 192.168.0.123:80; server_name www.site.com site.com; location /rss/main/ { uwsgi_pass unix:///tmp/site.com.sock; include uwsgi_params; } location / { rewrite ^ https://site.com$request_uri permanent; } } server { listen 192.168.0.123:443 ssl; server_name site.com; access_log /var/log/nginx/site.com_access.log; error_log /var/log/nginx/site.com_error.log; ssl_certificate /srv/ssl/site_com.crt; ssl_certificate_key /srv/ssl/site.com.key; location / { uwsgi_pass unix:///tmp/site.com.sock; include […]

如果只请求server_name,如何不redirect

大多数人在浏览器栏中键入: mysite.com而不是https://mysite.com 。 包括我自己在内的许多开发者在他们的Nginxconfiguration文件中都有类似的东西,这意味着这个mysite.com请求会导致redirect到https:// site: server { listen 80; server_name mysite.com; return 301 https://$server_name$request_uri; } 谷歌的网页速度团队最近表示,这些redirect对于移动性能来说尤其如此,因为redirect导致请求通过移动运营商networking返回。 我的问题是有没有其他的方式来编写nginx.conf,以便在server_nameinput的人不会遇到这个http://到https://redirect的惩罚?

nginx和owncloud,.htaccess安全警告

我对nginx和owncloud有问题。 当我访问owncloud的login页面,我得到这个错误: 您的数据目录和您的文件可能从互联网上访问。 ownCloud提供的.htaccess文件不起作用。 我们强烈build议您以不能再访问数据目录的方式configurationWeb服务器,或者将数据目录移到Web服务器文档根目录之外。 这是我的虚拟主机文件: server { listen 80; server_name default_server; root /usr/share/nginx/www; index index.html index.htm; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } […]

Keepalive是否存在套接字连接?

前简报: 尽pipe我的问题目的很广泛,但我正在处理连接到php-fpm(fcgi)的nginx,它通过本地套接字(/tmp/somesocket.socket)提供。 Nginx具有保持与fcgi后端连接的设置( http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_keep_conn )。 这是我的问题所涉及的。 题: 在linux中,当连接到本地套接字时,存在Keepalive这样的事情吗? 有一个连接保持活着删除(甚至一点点)与连接的创build/拆卸相关的一些开销? 谢谢。

在nginx和php-cgi上没有指定input文件

我试图在Windows PC上运行nginx和php-cgi,我已经到了要将html目录移回到两个目录的位置,所以我可以创build一个结构。 我现在唯一的问题是,PHP不会拿起任何.php文件。 我曾尝试加载一个静态HTML文件(localhost / test.html),它工作正常,但localhost / info.php根本不工作。 任何人都可以给我一些指导呢? 服务器块的一部分可以在下面find。 server { listen 80; server_name localhost; root ../../www; index index.html index.htm index.php; #charset koi8-r; #access_log logs/host.access.log main; location ~ \.php$ { fastcgi_pass 127.0.0.1:9123; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }

所有来自127.0.0.1的nginx访问日志(所以不能使用fail2ban)

问题 我试图configurationfail2ban来使用这里显示的块来阻止ddos攻击。 基本上它会查看所有请求,如果任何单个IP在60秒内发出超过240个请求,则会阻止它们两天。 但是,我的nginx访问中的所有日志都来自127.0.0.1,这使得整个事情毫无意义。 什么可能导致nginxlogging来自服务器的所有stream量? (我使用perusio的nginxconfiguration在LEMP堆栈上运行Drupal。)

nginx给我403禁止index.html,权限是正确的,configuration是从另一台服务器复制

所以,当我试图打击http://mayall.syniq.co.uk时,nginx给了我一个403 Forbidden错误页面,它应该像http://byrne.syniq.co那样向Rik Mayall吐出一个致敬页面。英国 (不应该花你很长时间来猜测我的命名scheme:))。 namei -l /www/vhosts/mayall.syniq.co.uk/public/index.html产生以下结果: f: /www/vhosts/mayall.syniq.co.uk/public/index.html drwxr-xr-x root root / drwxr-xr-x www-data www-data www drwxr-xr-x www-data www-data vhosts drwxr-xr-x www-data www-data mayall.syniq.co.uk drwxr-xr-x www-data www-data public -rw-r–r– www-data www-data index.html 所以这不是权限。 我的虚拟主机configuration如下: server { listen *:80; listen [::]:80; server_name mayall.syniq.co.uk; # Character Set charset utf-8; # Logs access_log /www/vhosts/mayall.syniq.co.uk/logs/access_log.nginx; error_log /www/vhosts/mayall.syniq.co.uk/logs/error_log.nginx; # […]