2018 Sep. 13.
http {
##
# Basic Settings
##
client_max_body_size 32M;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # 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_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
nginx再起動
# systemctl restart nginx.service
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
#index index.html index.htm index.nginx-debian.html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
設定ファイル正誤確認
# nginx -t
php-fpm ( FastCGI Process Manager )を再起動する
# systemctl restart php7.4-fpm.service
nginxを再起動する
ファイアウォール設定
# ufw allow proto tcp from 192.168.1.0/255.255.255.0 to any port 80# ufw allow proto tcp from 192.168.1.0/255.255.255.0 to any port 443
# ufw reload
関連ソフトインストール
# apt install nginx mysql-server# systemctl start nginx
# apt install php php-fpm php-mysql php-gettext php-common php-mbstring php-mbstring
php設定
/etc/php/7.2/fpm/php.ini を編集するcgi.fix_pathinfo=0
/etc/php/7.2/fpm/pool.d/www.conf を編集する
php_admin_value[memory_limit] = 128M
# service php7.2-fpm restart
nginx設定
/etc/nginx/sites-available/default を編集するserver {
}
の中に、下記を書き込む。
# ディレクトリ内のファイル一覧を表示する場合
autoindex on;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
confファイルを編集する
fastcgi_param PHP_VALUE "memory_limit = 128M";
次の1行の内容の/var/www/html/phpinfo.phpファイルを作成する
nginx起動
# systemctl restart nginxhttp://NGINX-SERVER/xxx
"xxx" にでたらめな文字列を入れてhttp://NGINX-SERVERにアクセスし、nginxから404 Not Foundが送られてくることを確認する
404 Not Found
http://NGINX-SERVER/phpinfo.php にアクセスしてphpinfo画面が表示されることを確認する