3 – Ubuntu 12.04 Web設定ガイド

0

カゴヤ・クラウド/VPS
/GMOクラウドのVPS
/さくらのVPS
にWebアプリケーションのための設定ファイルを準備します。

目標はMagentoのインストールです。

難しいことは抜きに、とりあえず真似すればインストールできるように記述しています。

事前に

Ubuntu 12.04 パーフェクトセッティングガイド

Ubuntu 12.04 Webアプリケーションセットアップガイド

の両方が終了しているものとします。

作業内容

  • PHP設定ファイルサンプル
  • nginx設定ファイルサンプル
  • nginx起動テスト

PHP-FPM設定ファイルSAMPLE

PHP-FPMの設定サンプルです。この通りにしろというのではありませんが、お勧め設定の参考としてください

[www]user = www-data
group = www-data

;listen = 127.0.0.1:9000
;listen.allowed_clients = 127.0.0.1

listen = /tmp/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0666

pm = dynamic
pm.max_children = 10
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 4
pm.max_requests = 500
pm.process_idle_timeout = 10s;

chdir = /

nginx設定ファイルSAMPLE

nginxの設定ファイルサンプルです。これも、この通りにしろというのではありませんが、お勧め設定の参考としてください(phpmyadmin用)

server {
	listen   80; ## listen for ipv4; this line is default and implied
	#listen   [::]:80 default_server ipv6only=on; ## listen for ipv6
	limit_conn limit_per_ip 16;
	location = /robots.txt  { access_log off; log_not_found off; }
	location = /favicon.ico { access_log off; log_not_found off; }
	location ~ /. { deny all; }
	location ~* .(js|css|png|jpg|jpeg|gif|ico)$ { expires 24h; }
	location ~* ^/tmp/ { deny all; }
	location / {
		deny all;
	}

	location /phpmyadmin {
		root /usr/share/;
		index index.php index.html index.htm;
		location ~ ^/phpmyadmin/(.+.php)$ {
			try_files $uri =404;
			root /usr/share/;
			fastcgi_pass				unix:/tmp/php5-fpm.sock;
			fastcgi_index				index.php;
			fastcgi_param SCRIPT_FILENAME	$document_root$fastcgi_script_name;
			fastcgi_connect_timeout 		60;
			fastcgi_send_timeout 			180;
			fastcgi_read_timeout 			180;
			fastcgi_buffer_size 			256k;
			fastcgi_buffers 				4 256k;
			fastcgi_busy_buffers_size		256k;
			fastcgi_temp_file_write_size		256k;
			fastcgi_intercept_errors on;
			fastcgi_param PATH_INFO		$fastcgi_path_info;
			fastcgi_param PATH_TRANSLATED	$document_root$fastcgi_path_info;
			fastcgi_param QUERY_STRING		$query_string;
			fastcgi_param REQUEST_METHOD	$request_method;
			fastcgi_param CONTENT_TYPE	$content_type;
			fastcgi_param CONTENT_LENGTH	$content_length;
			fastcgi_param SCRIPT_NAME		$fastcgi_script_name;
			fastcgi_param REQUEST_URI		$request_uri;
			fastcgi_param DOCUMENT_URI	$document_uri;
			fastcgi_param DOCUMENT_ROOT	$document_root;
			fastcgi_param SERVER_PROTOCOL	$server_protocol;
			fastcgi_param GATEWAY_INTERFACE	CGI/1.1;
			fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
			fastcgi_param REMOTE_ADDR		$remote_addr;
			fastcgi_param REMOTE_PORT		$remote_port;
			fastcgi_param SERVER_ADDR		$server_addr;
			fastcgi_param SERVER_PORT		$server_port;
			fastcgi_param SERVER_NAME		$server_name;
			include /etc/nginx/fastcgi_params;
	}
		location ~* ^/phpmyadmin/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
		root /usr/share/;
		}
	}
	location /phpMyAdmin {
		rewrite ^/* /phpmyadmin last;
	}
}

nginx.conf

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;

events {
        worker_connections 512;
}

http {

	limit_conn_zone $binary_remote_addr zone=limit_per_ip:16m;

	gzip on;
	gzip_vary   on;
	gzip_disable "MSIE [1-6].";
	gzip_min_length   1100;
	gzip_buffers      32 8k;
	gzip_http_version 1.0;
	gzip_comp_level 5;
	gzip_proxied    any;
	gzip_types      text/plain text/css text/javascript text/xml application/x-javascript application/xml application/xml+rss;

	 client_body_buffer_size 256k;
	 client_body_in_file_only off;
	 client_body_timeout 60s;
	 client_header_buffer_size 256k;
	## how long a connection has to complete sending 
	## it's headers for request to be processed
	 client_header_timeout  20s;
	 client_max_body_size 128m; 
	 connection_pool_size  256;
	 directio  4m;
	 ignore_invalid_headers on;       
	 large_client_header_buffers 4 256k;
	 output_buffers   4 256k;
	 postpone_output  1460;
	 proxy_temp_path  /tmp/nginx_proxy/;
	 request_pool_size  32k;
	 reset_timedout_connection on;
	 send_timeout     60s;

	open_file_cache max=5000 inactive=30s;
	open_file_cache_valid 120s;
	open_file_cache_min_uses 2;
	open_file_cache_errors off;

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
# 
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

設定ファイルが正しく動くかテストします

service nginx configtest

 

Testing nginx configuration: nginx.

うまく動いたらリスタートします

service nginx restart

 次にPHP-FPMをリスタートします

service php5-fpm restart

phpMyAdminに接続してみてください

http://あなたのサイトアドレス/phpmyadmin

Share.

About Author

Leave A Reply

CAPTCHA