Fedora-28-lnmp-安装-Nginx-php

# nginx php7
#关闭或开启selinux,可自行判断
dnf -y install nginx mariadb
dnf -y install php php-pear php-devel php-fpm php-mysqli php-gd php-cgi php-curl php-mbstring php-bcmath php-redis php-memcached php-memcache php-apc git
dnf -y install mariadb mariadb-server
dnf -y install zsh htop iftop axel jq lsof vim make gcc unzip memcached redis mlocate fail2ban mod_ssl
updatedb

#vim
cat >>~/.vimrc<<EOF
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
:colorscheme desert
:set ts=2
:set expandtab
:%retab!
EOF

#sysctl
cat >/etc/sysctl.conf<<EOF
net.ipv4.icmp_echo_ignore_all = 1
net.ipv4.tcp_congestion_control = bbr
net.core.default_qdisc = fq
EOF

#firewalld
systemctl start firewalld
systemctl enable firewalld
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=http
firewall-cmd --add-service=https --permanent
firewall-cmd --add-service=https

#nginx
echo "" > /usr/share/nginx/html/index.html;
echo "" > /usr/share/nginx/html/404.html;
echo "" > /usr/share/nginx/html/50x.html;
sed -i '29a\ \ \ \ server_tokens off;' /etc/nginx/nginx.conf;
sed -i "29a\ \ \ \ client_max_body_size 100M;" /etc/nginx/nginx.conf

#php
sed -i "s/expose_php\ =\ On/expose_php\ =\ Off/g"  /etc/php.ini
sed -i "s/upload_max_filesize\ =\ 2M/upload_max_filesize\ =\ 200M/g" /etc/php.ini
sed -i "s/post_max_size\ =\ 8M/post_max_size\ =\ 200M/g" /etc/php.ini
sed -i "s/max_execution_time\ =\ 30/max_execution_time\ =\ 300/g" /etc/php.ini
sed -i "s/max_input_time\ =\ 60/max_input_time\ =\ 300/g" /etc/php.ini
sed -i "s/memory_limit\ =\ 128M/memory_limit\ =\ 1280M/g" /etc/php.ini
sed -i "24s/apache/nginx/g" /etc/php-fpm.d/www.conf
sed -i "26s/apache/nginx/g" /etc/php-fpm.d/www.conf
chown -R nginx:nginx /var/lib/php/

#system
systemctl enable php-fpm;
systemctl start php-fpm;
systemctl enable nginx;
systemctl restart nginx;
systemctl start mariadb;
systemctl enable mariadb;

#nginx 运行php
vim /etc/nginx/conf.d/domain.conf

server {
    server_name  domain ;
    root         /home/domain/public_html;
    #access_log   /home/domain/logs/access.log main;
    #error_log    /home/domain/logs/error.log;
    #rewrite ^(.*)$  https://$host$1 permanent;
    location / {
      proxy_connect_timeout 600s;
      proxy_send_timeout   600;
      proxy_read_timeout   600;
      proxy_buffer_size    64k;
      proxy_buffers     16 32k;
      proxy_busy_buffers_size 64k;
      proxy_temp_file_write_size 64k;
      proxy_pass_header Set-Cookie;
      proxy_redirect     off;
      proxy_hide_header  Vary;
      proxy_ignore_headers Cache-Control Expires;
      proxy_set_header   Referer $http_referer;
      proxy_set_header   Host   $host;
      proxy_set_header   Cookie $http_cookie;
      proxy_set_header   X-Real-IP  $remote_addr;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ^~ /.git/ {
        return 404;
    }

    location ~* \.(log)$ {
        return 404;
    }

    location ~ \.php$ {
        fastcgi_read_timeout 600;
        fastcgi_pass unix:/run/php-fpm/www.sock;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include       fastcgi_params;
    }

    index index.html index.htm index.php;
    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}