安装nginx 和 php

apt install nginx php-fpm

配置php端口
/etc/php/7.0/fpm/pool.d/www.conf,36行附近

;listen = /run/php/php7.0-fpm.sock
listen = 127.0.0.1:9001

配置nginx,动静分离

server {
    root /var/www;
    error_log /var/www/log/err.log error;

    location / {
        try_files $uri $uri/ =404;
        index index.php;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9001;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
        include        fastcgi_params;
    }

    listen [::]:443 ssl ipv6only=on;
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/你的域名/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/你的域名/privkey.pem;

    ssl_session_cache shared:le_nginx_SSL:1m;
    ssl_session_timeout 1440m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";
}

把上面的“你的域名”改成你自己的域名
然后重启nginx和php-fpm

systemctl restart nginx
systemctl restart php7.0-fpm

另外,PHP访问某些API接口可能会出现问题,模拟成浏览器访问即可
php.ini,833行附近

; Define the User-Agent string. PHP's default setting for this is empty.
; http://php.net/user-agent
user_agent="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; GreenBrowser)"

如果出现错误500想要知道原因
php.ini

; display_errors Off
display_errors On

安装拓展之类的

apt install php7.0-curl
apt install php7.0-mbstring
apt install php7.0-mysql

另外,这里有个坑。
直接安装这些就行了,不需要在php.ini里去掉extension前面的分号。

标签: 网站, Nginx, PHP

添加新评论