Articles of nginx

Nginx + HHVM + MariaDB + WordPress安装 – >build立数据库连接时出错

我正在为WordPress博客设置一个VPS 。 我使用Ubuntu 14.04 LTS 64位,然后我安装了Nginx 1.7.8,HHVM 3.6.0,MariaDB(不记得版本)。 最后,我下载了WordPress 4.1.1,创build数据库并使用正确的参数(数据库名称,用户名和密码)编辑wp-config.php文件后,尝试连接到博客进行设置。 我之前做过这种安装,但几个月前,我不记得有任何问题。 但是,在尝试了解我所知道的一切之后, 我无法解决问题 :每次我尝试在浏览器上加载博客以启动最终的WordPress安装过程(名称,pipe理员和密码的表单)时,我都会看到这个传奇的,可怕的消息: Error establishing a database connection 事实是,MySQL正在运行,但我不明白的是错误的。 我在我的博客的根目录下创build了一个testconnection.php文件,内容如下 <?php $link = mysql_connect('localhost', 'root', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($link); ?> 当然,使用正确的密码进行编辑。 当我在浏览器中加载该php文件时,我得到一个 "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" 该文件不在任何地方,我的/etc/mysql/my.cnf指向/var/run/mysql/mysqld.sock […]

nginx正则expression式的位置不匹配

我有下面的位置,这是一个更大的conf文件。 作为参考,这工作: location = /scripts/news/admin/index.js { alias /my/file/path/news/scripts/admin/index.js; } 但是,这不能拿起正则expression式(作为一个testing我强制文件path,但它仍然没有使用): location ^~ ^/scripts/([az]+)/([az]+)/([az]+).js$ { alias /my/file/path/news/scripts/admin/index.js; # for testing, use direct file location break; # ensuring nothing else happens, for testing #alias /my/file/path/$1/scripts/$2/$3.js; # actual regex } 我在我的正则expression式中明显缺less一些明显的东西吗? 我试过(.*)和~*但是没有任何区别。 正在使用的url是: http://example.com/scripts/news/admin/index.js 在我的日志中,我看到: 2015/03/21 20:43:28 [debug] 16440#0: *183689 test location: "^/scripts/(\w+)/(\w+)\.js$" 2015/03/21 20:43:28 [debug] 16440#0: *183689 […]

使用Nginx作为Web服务器和反向代理

我正在尝试将Nginx设置为反向代理和Web服务器。 我在试图了解如何做到这一点上遇到了问题。 假设我使用了默认的Symfony2 nginxconfiguration( http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html ): server { server_name example.com www.example.com; root /var/www/project/web; location / { # try to serve file directly, fallback to app.php try_files $uri /app.php$is_args$args; } # DEV # This rule should only be placed on your development environment # In production, don't include this and don't deploy app_dev.php or config.php location […]

当应用程序重新加载时,让Nginx保持请求

我有一个nginx反向代理服务器设置为通过proxy_pass http://localhost:5000;转发请求到端口5000上运行的应用程序proxy_pass http://localhost:5000; 。 这工作,但是当我重新启动应用程序,大约10秒任何请求立即返回502 Bad Gateway ,直到应用程序重新加载。 有没有什么办法可以让Nginx在应用程序closures时保存这些请求,每隔一段时间重试一次呢? 我试过了 upstream backend { server localhost:5000 fail_timeout=20s; server localhost:5000 backup; } … proxy_pass http://backend; 但是这似乎没有效果。

Nginx位置=不工作

我有两个站点,我需要服务:一个静态的和dynamic的(Rails应用程序,实际上并不重要)。 我正在考虑以下内容: 请求到domain.com/ =>静态网站 请求domain.com/anything =>dynamic网站 对于这种情况, Nginx的位置指令看起来非常完美: server { listen 80; server_name www.domain.com *.domain.com; # Static match. Any exact match enters here location = / { root /link/to/static/folder; index index.html; } # Dynamic match location / { root /link/to/dynamic/folder; proxy_pass unix_socket_defined_above; } } 但是每当我向domain.com发出请求时,它都会被引导到dynamic匹配。 我错过了什么? 编辑:虽然它不是最佳的,我正在实现所需的function与以下声明: server { listen 80; server_name domain.com .domain.com; # […]

拒绝连接到“http:// someURL”,因为它违反了以下内容安全策略指令:“connect-src http:// someURL”

那么,这是从我的浏览器控制台出现的错误,我正在使用一个域,该域只有一个子域,我仍然无法访问子域。 其实我正在接受一些其他的错误。 我的猜测是我的错误是在add_header Content-Security-Policy ,在connect-src部分。 :这是域部分和Content-Security-Policy : server { large_client_header_buffers 1 1K; listen 80; server_name www.just4bettors.mobi just4bettors.mobi; root /home/c0pt/capilleira/capilleiraclickandgamblemobile/www; location / { index index.html index.htm; … } add_header Content-Security-Policy "default-src 'self' http://just4bettors.mobi:1337; connect-src http://just4bettors.mobi http://just4bettors.mobi:1337 http://www.just4bettors.mobi http://www.just4bettors.mobi:1337"; } 这是子域的一部分: server { listen 80; server_name www.desktop.just4bettors.mobi desktop.just4bettors.mobi; root /home/c0pt/capilleira/capilleiraclickandgambleweb/dist; location / { index index.html index.htm; … […]

将nginx置于某些IP的维护模式

因为if语句工作在nginx(没有嵌套,没有多个条件)的方式,我想不出一种方法来结合这两个function: 使用nginx Geo模块我有一个允许的ips列表 在我的文件系统上,如果我在特定的目录中touch appname ,应用程序会自动进入503维护模式。 这是我想要做的,但在nginx中不允许: location / { if (-f /var/www/maintmode/appname && $allowed_ip = no) { return 503; } try_files $uri; } 如果在nginx中可以实现上述function,那么来自Geo模块的allowed_ip列表中的任何人都将绕过503,并照常使用该站点。 然后,在validation应用程序正在从maint目录工作rm appname和503维护模式结束。 这种方法的好处是可以touch单个文件来启用/禁用maint模式,而无需修改conf并重新加载nginx。 任何想法,我怎么能得到这样的东西工作?

为什么abtesting中的Apache 2.4.7与NginX 1.4.6一样快呢?

我现在很困惑 我一直使用Nginx来提供静态文件,并将PHP传递给Apache。 我build了一个新的4GB内存盒,用mpm_prefork模块和NginX 1.4.6安装了Apache 2.4.7。 我设置了我所需要的,并决定运行一些abtesting。 我对我所看到的感到震惊。 在每个abtesting中,Apache都和Nginx一样。 这适用于Apache 2.4吗? 我已经读过关于2.4的性能升级,但是在过去NginX会摧毁Apache。 我错过了什么吗? 阿帕奇: Concurrency Level: 100 Time taken for tests: 1.157 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 279000 bytes HTML transferred: 21000 bytes Requests per second: 864.65 [#/sec] (mean) Time per request: 115.654 [ms] (mean) Time per request: 1.157 [ms] (mean, across […]

nginx:为每个域设置一个webmail(通配域?)

我想设置一个networkingmail. 为我的服务器上的每个域使用nginx的子域。 它似乎在https://mail.mydomain.com上工作,但我也可以通过访问不需要的服务器IP地址( https:// xxxx )来访问networking邮件。 这是我的Web邮件的conf文件: ### # Webmail (Rainloop) ### server { listen 80; server_name mail*.; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name mail*.; ssl_certificate /etc/ssl/nginx/server.crt; ssl_certificate_key /etc/ssl/nginx/server.key; ssl_protocols SSLv3 TLSv1; ssl_ciphers HIGH:!aNULL:!MD5; access_log /var/log/nginx/app-webmail.access.log; error_log /var/log/nginx/app-webmail.error.log; location / { root /var/www/rainloop; index index.html index.htm index.php; location ~ [^/]\.php(/|$) { […]

了解压力testing结果

所以我在最便宜的Digital Ocean层上运行我的基于Wordpress的网站进行了压力testing。 我使用WP超级caching在服务器端caching和Nginx作为我的Web服务器。 我也使用Cloudlfare作为我的CDN,并在我的网站中使用了免费的SSL。 我使用loader.io做了一些testing,得到了以下结果。 我在我的服务器上运行Ubuntu 14.04 64位。 我已经看过负载testing网站了解结果页面,但我并不真正了解内容。 http://ldr.io/1F45Y9G 我真的不希望在我的网站上获得任何stream量,我只是想了解所有这些东西是如何工作的。 那么这些性能结果究竟意味着什么呢? 还有什么可以进一步优化我的网站? 我的网站是dikshant.net