Articles of nginx

将htaccess重写规则转换为nginx

通过search互联网“转换htaccess的nginx规则”我想出了anilcetin和winginx .htaccess的nginx转换器,我怀疑它不能正确输出我所需要的。 以下哪项更准确? 你能帮我解决这个问题吗? 这是我想要转换为Nginx的.htaccess: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ %{ENV:BASE} index.php [QSA,L] 以下是转换器的输出。 Anilcetin if (!-f $request_filename){ set $rule_0 1$rule_0; } if ($rule_0 = "1"){ #ignored: "-" thing used or unknown variable in regex/rew } Winginx # nginx configuration location / { if (!-e $request_filename){ rewrite ^(.*)$ /$env_base index.php break; } }

configurationnginx在某些情况下发生代理通过,否则使用php fastcgi

当我发现访问者是一个爬虫(给SEO优化的网站)和一个标准的php fast-cgi实例(通过fastcgi pass)时,我有一个特定的情况,我想将访问者redirect到“prerender”除此以外。 我对nginx的经验非常稀less,所以我无法完成我所需要的。 这是我当前configuration的草稿 server { server_name example.com; root /vagrant/example.com/web; index app.php; location /phpmyadmin { root /usr/share; index index.php; location ~* \.php { fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } } location / { try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ /app.php/$1 last; } […]

nginx – 没有爬虫/机器人的ssl

在nginx中的端口80的服务器指令中,如果用户代理不是bot,我想将所有请求redirect到https。 我试着用这个: … location / { if ($http_user_agent !~* (bot|spider|crawler|sniffer|facebook) ) { return 301 https://host.com$request_uri; } include other-stuff.inc; } 我以为nginx将停止return但它不会。 它仍然处理include (它服务于正常的站点)并且不redirect。 (如果我评论include它做redirect,虽然)。 顺便说一句: break也行不通。

Nginx – 分支位置上下文中的参数

我正在尝试使用HttpEchoModule睡一个随机的时间,当我用特定的参数打一个位置: location = /api/shouldSend { if ($arg_blah = "test") { set_random $res 0 25; echo_sleep $res; } add_header Content-Type text/plain; echo_location /some_other_location; } 如果“如果”被删除,睡觉和移动到一个新的位置按预期工作,但我真的需要在这里检查参数。 搞清楚,这不起作用,我遇到了这篇文章: http : //wiki.nginx.org/IfIsEvil 。 没有一个解决方法似乎是适当的。 还有什么我可以在这里做? 谢谢!

不能去使用nginx和Express.JS路由

所以我把express.js设置在nginx后面,当我去到website.com/users ,我得到了404。但是当我去到website.com ,页面加载正常。 这似乎也是所有其他路线,我也无法访问website.com/public/css 。 这是我的nginxconfiguration upstream default { server 127.0.0.1:3000; keepalive 8; } server { listen 0.0.0.0:80; listen [::]:80 default_server ipv6only=on; root /var/www/; index index.html index.htm; # Make site accessible from http://localhost/ server_name website.com default; access_log /var/log/nginx/default.log; return 301 https://website.com$request_uri; location / { 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 […]

如何解决nginx 413错误?

我在使用nginx的laravel伪造网站上遇到了413错误。 我更新了cli和ftp的php.ini到1000m,并更新了我的nginxconfigurationclient_max_body_size = 1000m。 仍然得到413.我想上传的文件是6兆字节。 有没有一个日志文件,我可以仔细阅读,这将有助于我进一步排除故障? 我应该如何更好地解决这个错误?

如何使用nginx将PHP文件路由到2个不同的后端

我有一个运行Nginx的服务器,它正在使用以下位置指令将所有PHP脚本代理到Apache: location ~ \.php$ { proxy_pass http://@apache; } 我想介绍一个新的位置指令,如: location ~* ^/blog/(.*\.php)$ { alias /opt/blog/public; fastcgi_pass @phpfpm; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; include fastcgi_params; } 但是,当我访问http://example.com/blog/test.php我打Apache,而不是PHP的FPM。 我怎样才能使新的位置指令优先于Apache的位置?

PHP-FPM TCP连接没有及时终止

我使用APCcaching(通过W3 Total Cache插件)通过nginx / PHP5-FPM提供Wordpress页面。 Nginx通过端口9000上的TCP套接字与PHP-FPM进行通信。我已经通过sysctl调整了最大连接数为1024.我已经将max_execution_time(在php.ini中)和request_terminate_timeout(在FPM conf文件中)设置为30秒。 时不时地(每隔8-10个小时,而不是线性地),端口9000上的开放TCP连接数量增长到接近1000(主要是CLOSE_WAIT状态,一些FIN_WAIT,FIN_WAIT_2),有时会超过1000,并且我的Web服务器启动返回504错误。 一旦我终止该端口上的所有TCP连接并重新启动FPM,它就会再次正常工作。 我启用了缓慢的日志,看看发生了什么,如果我正确地阅读它,它挂在apc_store()调用。 这是一个APCconfiguration错误,还是我需要调整与FPM设置? 有没有办法强制这些TCP连接终止,即使脚本不发送最终的终止信号? 来自FPM慢日志的示例跟踪: [22-Jan-2015 09:42:49] [pool www] pid 20327 script_filename = /var/www/index.php [0x00007fdc527ec908] apc_store() /var/www/wp-content/plugins/w3-total-cache/lib/W3/Cache/Apc.php:55 [0x00007fdc527ec768] set() /var/www/wp-content/plugins/w3-total-cache/lib/W3/ObjectCache.php:254 [0x00007fdc527ec5e0] set() /var/www/wp-content/plugins/w3-total-cache/lib/W3/ObjectCache.php:300 [0x00007fdc527ec488] add() /var/www/wp-content/plugins/w3-total-cache/lib/W3/ObjectCacheBridge.php:73 [0x00007fdc527ec330] add() /var/www/wp-content/object-cache.php:94 [0x00007fdc527ec200] wp_cache_add() /var/www/wp-includes/option.php:176 [0x00007fdc527ec078] wp_load_alloptions() /var/www/wp-includes/functions.php:1272 [0x00007fdc527ebf40] is_blog_installed() /var/www/wp-includes/load.php:474 [0x00007fdc527ebdb0] wp_not_installed() /var/www/wp-settings.php:109 [0x00007fdc527ebc88] +++ dump failed

使用node.jsconfigurationnginx proxypass

我正在尝试使用ProxyPassfunction使用nginx运行node.js应用程序; 我的node.js应用程序在localhost:8888执行,这是我的nginxconfiguration文件 server { listen 80; ## listen for ipv4; this line is default and implied server_name mywebsiteexample.com:80; location / { proxy_pass http://localhost:8888/; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /doc/ { alias /usr/share/doc/; autoindex on; allow 127.0.0.1; deny all; } } 然后当我去我的网页(www.mywebsiteexample.com); 服务器响应好,但没有find相关的文件(CSS,图像等)。

Nginx的重写模块无法正常工作

我已经阅读了很多关于它的主题,但是解决不了我的问题。 从APache移动到Nginx后,我不能设置重写来处理我的论坛友好的url。 我的论坛位于虚拟服务器的/论坛/位置。 我想要做的就是将/forum/thred-something.html&someaction重写到/forum/showthread.php?tid=ID&action=someaction 我使用这个插件进行名称到ID的转换: https : //github.com/frostschutz/MyBB-Google-SEO 这就是我的虚拟服务器本地化configuration看起来像: server { server_name www.podziemieopowiadan.pl; listen 80; return 301 http://podziemieopowiadan.pl/index.php; } server { server_name podziemieopowiadan.pl; listen 80; access_log /var/log/nginx/podziemieopowiadan-pl_access_log; error_log /var/log/nginx/podziemieopowiadan-pl_error_log; root /var/www/domains/podziemieopowiadan-old; index index.php; allow 188.127.246.50; allow 188.127.242.122; allow 204.93.240.0; allow 204.93.177.0; allow 199.27.128.0; allow 173.245.48.0; allow 103.21.244.0; allow 103.22.200.0; allow 103.31.4.0; allow 141.101.64.0; allow 108.162.192.0; […]