Alpine 安装Nginx + PHP 以及YAML等扩展
1 安装Nginx
apk add nginx
2 修改Nginx默认配置
rm /etc/nginx/conf.d/default.conf
echo '''
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name _;
index index.html index.htm index.php;
root /home/wwwroot/default;
location ~ [^/]\.php(/|$) {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# You may need this to prevent return 404 recursion.
location = /404.html {
internal;
}
}
''' > /etc/nginx/conf.d/mydomain.com.conf
3 安装PHP及相关拓展
apk add php81 php81-mbstring php81-json php81-zlib php81-session php81-fpm php81-ctype php81-sqlite3 php-pear php81-pecl-yaml
4 修改PHP相关配置
sed -i "s@^memory_limit.*@memory_limit = 5M@" /etc/php81/php.ini
sed -i 's@^output_buffering =@output_buffering = On\noutput_buffering =@' /etc/php81/php.ini
sed -i 's@^;cgi.fix_pathinfo.*@cgi.fix_pathinfo=1@' /etc/php81/php.ini
sed -i 's@^short_open_tag = Off@short_open_tag = On@' /etc/php81/php.ini
sed -i 's@^expose_php = On@expose_php = Off@' /etc/php81/php.ini
sed -i 's@^request_order.*@request_order = "CGP"@' /etc/php81/php.ini
sed -i 's@^;date.timezone.*@date.timezone = Asia/Shanghai@' /etc/php81/php.ini
sed -i 's@^post_max_size.*@post_max_size = 100M@' /etc/php81/php.ini
sed -i 's@^upload_max_filesize.*@upload_max_filesize = 50M@' /etc/php81/php.ini
sed -i 's@^max_execution_time.*@max_execution_time = 600@' /etc/php81/php.ini
sed -i 's@^;realpath_cache_size.*@realpath_cache_size = 2M@' /etc/php81/php.ini
sed -i 's@^disable_functions.*@disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,popen@' /etc/php81/php.ini
5 创建网站目录
mkdir /home/wwwroot
mkdir /home/wwwroot/mydomain.com
6 安装ACME.sh签发证书
curl https://get.acme.sh | sh
alias acme.sh=~/.acme.sh/acme.sh
acme.sh --issue -d mydomain.com --webroot /home/wwwroot/mydomain.com/
acme.sh --installcert -d mydomain.com \
--keypath /home/wwwroot/ssl/mydomain.com/.key \
--fullchainpath /home/wwwroot/ssl/mydomain.com \
--reloadcmd "service nginx reload"
6 修改Nginx配置文件
server {
listen 443 ssl;
server_name mydomain.com;
root /home/wwwroot/mydomain.com;
ssl_certificate "/home/wwwroot/mydomain.com/mydomain.com.cer";
ssl_certificate_key "/home/wwwroot/mydomain.com/mydomain.com.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
}
7 重启PHP、Nginx并添加开机启动
/etc/init.d/php-fpm81 restart
rc-update add php-fpm7
/etc/init.d/nginx restart
rc-update add nginx
1 评论
8ffwy6