# apt-get install nginx
Install php5
# apt install php-fpm php-mysql
Install php7.0
# apt install php7.0-fpm php7.0-mysql
Edit the config default in path /etc/nginx/nginx.conf, this config basic with php
------------------------------------------------------------------------------------------------
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
client_max_body_size 10M;
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; # 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 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;
#--------------------------------
# Dfine Virtual Host Configs
#--------------------------------
# Server not name trow not found
server {
return 404;
}
# Force and redirect to htttps mydomain.com
server {
listen 80;
server_name mydomain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
root /home/app/mydomain.com/html;
# File open default
index index.php;
server_name mydomain.com;
# path certificate public and private key
ssl_certificate /home/app/ssl/mydomain.com.crt;
ssl_certificate_key /home/app/ssl/mydomain.com.key;
#Limit size file
client_max_body_size 15M;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# unless the request is for a valid file, send to bootstrap
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/app/mydomain.com/html;
}
#pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht
{
deny all;
}
}
}
----------------------------------------------------------------------------------------------
Check config current
# nginx -c /etc/nginx/nginx.conf -t
Reload or Restart service nginx
# /etc/init.d/nginx reload
or
#/etc/init.d/nginx restart
0 Comments