Archive for the ‘nginx’ Category

 

nginx rewrite

8月 31st, 2013

nginx で rewrite ファイルが無いときだけ、phpに渡す方法 server {  listen       20961;  root /home/www/web_api;  access_log   /var/log/nginx/com.access.log  main;  error_log   /var/log/nginx/com.error.log;  location /bid/ {    index   index.php index.html;    try_files $uri @rewriteapp;  }  location @rewriteapp{    rewrite ^/(.*)$ /index.php last;  }  location /index.php {    fastcgi_pass unix:/var/run/php-fpm/www.socket;    fastcgi_index index.php;    include fastcgi_params;  } } […]

Read full article | コメントは受け付けていません。

php-fpm + nginx

8月 31st, 2013

fpm socket or tcp http://lowendtalk.com/discussion/7289/nginx-php-fpm-unix-socket-or-tcp-ip-for-fastcgi-pass https://github.com/perusio/php-fpm-example-config 5.3.8まではtcpのほうが良い? http://wiki.nginx.org/PHPFcgiExample /etc/php-fpm.d/www.conf php 5.4.19なので tcpをsocketにしてみる。 ; listen = 127.0.0.1:9000 listen = /var/run/php-fpm/www.socket apacheをnginxに変更 user = nginx ; RPM: Keep a group allowed to write in log dir. group = nginx # /etc/init.d/php-fpm start Starting php-fpm: [ OK ] でエラーが出なければOK * phpのいろいろ更新したのでエラーが出た、ライブラリを再構築しました。 /etc/nginx/fastcgi_params fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; fastcgi_param  PATH_INFO […]

Read full article | コメントは受け付けていません。

ファイルサイズ関連

7月 19th, 2013

* nginx  client_max_body_size 16M; * httpd , php  LimitRequestBody 1000000  php_value  upload_max_filesize  16M  php_value post_max_size 16M  php_value max_execution_time 60  php_value max_input_time 60 * form この辺

Read full article | コメントは受け付けていません。

nginx + eval + memcached : check block id

4月 1st, 2013

API認証をどうしようかと memcachedにブロックidを入れて、チェックしようと思います。 1. nginx でmemcachedからデータを取得 ng => 403 ok => 2 2. アプリケーションサーバーへ idが正常 => データを返す + ログをfluentdへ流す => 3, idが不正(桁数や簡単な法則チェックのみ) => memcachedへblockidとして登録。403を返す。 ipチェックもする 3. 正常時 fluentd + redisでidカウンタ 数値が上がったらアラート →異常値→4 4. 異常値確認 異常値だったらmemachedへblockidとして登録 // 別プロセスで定期的にredisをチェック。 これでいけそうです。 /// インストール http://blog.bbtune.com/archives/2412/nginx-exchange-header 以前と同じ方法でrpmを作ります。 https://github.com/agentzh/nginx-eval-module 1.0.3を使わせていただきます。    –add-module=/tmp/nginx/headers-more-nginx-module-0.19rc1\    –add-module=/tmp/nginx/nginx-eval-module-1.0.3\ debugバージョンと2つあるので両方入れておきます。 nginx conf upstream api_server {  server 127.0.0.1:30101; […]

Read full article | コメントは受け付けていません。

nginx headerを書き換える

2月 24th, 2013

http://wiki.nginx.org/HttpHeadersMoreModule#more_set_headers * headers-more-nginx-moduleの最新版をダウンロードして https://github.com/agentzh/headers-more-nginx-module/tags 0.19をダウンロードして展開。 /path/to/headers-more-nginx-module-0.19 * インストール centos 6用のソースを利用するため http://nginx.org/packages/centos/6/SRPMS/nginx-1.2.7-1.el6.ngx.src.rpm をダウンロードしておきます。 # rpm -ivh nginx-1.2.7-1.el6.ngx.src.rpm 警告: nginx-release-centos-6-0.el6.ngx.src.rpm: ヘッダ V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY ########################################### [100%] specファイルを編集 # vim /root/rpmbuild/SPECS/nginx.spec オプション設定部分に –add-module=/path/to/headers-more-nginx-module を追加します。 %build ./configure \        –prefix=%{_sysconfdir}/nginx \        –sbin-path=%{_sbindir}/nginx \        –conf-path=%{_sysconfdir}/nginx/nginx.conf \     […]

Read full article | コメントは受け付けていません。

nginx メンテナンスページへリダイレクト 405 Not Allowed. can not post to static page!

2月 13th, 2013

ページを返すパス(/action/)にアクセスしたら maintenance.html か ajaxパターンだったら .jsonを返す。 systemディレクトリはキャッシュしないように 0を指定。 messagepackを使っていたので、それようのヘッダーを返すように追加  location /action/ {    rewrite ^/actction/game/.*/\-/.*  /system/maintenance.msgpack last;    rewrite ^ /system/maintenance.html last;    return 404;  }  location ^~ /system {    root    /home/catwork.mixi/web;    expires 0;    types {      “application/x-msgpack;charset=x-user-defined” msgpack;      application/json json;    }    default_type text/html;  } と書いたのですが、POSTすると 404 […]

Read full article | コメントは受け付けていません。

nginx | ポートのデフォルトサーバーを設定。set default server for a port.

12月 25th, 2012

http://nginx.org/en/docs/http/request_processing.html#mixed_name_ip_based_servers server {    listen      80 default_server;    server_name example.net www.example.net;    … } default_serverを付けているserverが設定されていないserver_nameにアクセスされたときに呼ばれる。 何も設定しないと最後に読まれたconfigになる様子。

Read full article | コメントは受け付けていません。

wordpressをnginxでリバースプロキシーしたときの404がキャッシュされなかったり、phpにアクセスされないようにしたり。

12月 11th, 2012

wordpressをnginxでリバースプロキシーしたときの404がキャッシュされなかったり、phpにアクセスされないようにしたり。 結局、404を上手くキャッシュ出来ずに。数時間。目が痛い。。。 server { # simple reverse-proxy  proxy_ignore_headers Cache-Control Expires;  if ( $uri ~ php$ ){    set $my404 1;  }  if ( $uri ~ ^/wp-admin ){    set $my404 1;  }  if ( $my404 = 1 ) {    rewrite      / /error/404.html last;  }  location / {    proxy_pass      http://mybackend; […]

Read full article | コメントは受け付けていません。

nginx 1.0.15 でリバースプロキシー

11月 7th, 2012

http://nginx.org/ プロキシーサーバーを入れておこうと思い。 アプリケーションサーバーのhttpもnginxにしたいけど今は時間的に(pythonに書き換えたい部分とか気になる)無理 さくらのVPSでyumで nginx.x86_64 1.0.15-2.el6 http://nginx.org/ をみたり、いくつか記事を見た感じでは、1.0.15で良さそう。 http://wiki.nginx.org/FullExample シンプルな利用なので、ここのサンプルだけ十分いけそうです。 と思いましたが、最初は普通に詳細をみたほうが良いようです。proxy設定とか http://wiki.nginx.org/HttpProxyModule http://nginx.org/en/docs/http/ngx_http_proxy_module.html /etc/nginx/proxy.conf を作成 proxy_redirect          off; proxy_set_header        Host            $host; proxy_set_header        X-Real-IP       $remote_addr; proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size    1m; client_body_buffer_size 128k; proxy_connect_timeout   10; […]

Read full article | コメントは受け付けていません。