Nginx の設定

インストール

# インストール
$ sudo apt-get -y install nginx
# 設定ファイルのバックアップ
$ sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.org
$ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.org
# デフォルト設定の削除
$ sudo rm /etc/nginx/sites-enabled/default

PHP 設定

nginx で PHP を動かすためには、PHP-FPM のインストールと設定が必要です。

# インストール
$ sudo apt-get -y install php-fpm
# 自動起動設定
$ sudo sysv-rc-conf php-fpm on

nginx の設定

キープアライブ時間と、server_names_hash_bucket_size を 128 に変更。

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

	server_names_hash_bucket_size 128;
	# server_name_in_redirect off;

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

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	gzip_vary on;
	gzip_proxied any;
	gzip_comp_level 1;
	gzip_buffers 16 8k;
	gzip_http_version 1.0;
	gzip_types	text/css
				text/javascript
				text/plain
				text/xml
				application/javascript
				application/json
				application/xml
				application/xml+rss;

最低限のサーバー設定と、php-fpm 呼び出し設定を行います。

server {
	listen		80;
	root		/var/www/html;
	index		index.php index.html index.htm;
	try_files	$uri $uri/ /index.php;

	location ~ \.php$ {
		fastcgi_pass	unix:/var/run/php/php7.0-fpm.sock;
		fastcgi_index	index.php;
		fastcgi_param	SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include			fastcgi_params;
	}
}

nginx を再起動。

$ sudo service nginx restart

ubuntu/v1604/nginx_の設定.txt · 最終更新: 2018/03/18 09:56 (外部編集)
 
特に明示されていない限り、本Wikiの内容は次のライセンスに従います: CC Attribution-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki