php
php7.3.5
镜像sudo docker pull php:7.3.5-fpm
sudo mkdir -p /http/htdocs
sudo docker run --name php-fpm -v /http/htdocs:/www -d php:7.3.5-fpm
nginx
nginx1.16.0
镜像sudo docker pull nginx:1.16.0
sudo mkdir -p /http/nginx/logs /http/nginx/conf /http/nginx/conf.d
/http/nginx/conf/nginx.conf
sudo touch /http/nginx/conf/nginx.conf
创建文件,编辑文件内容如下user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
/http/nginx/conf.d/www.conf
sudo touch /http/nginx/conf.d/www.conf
创建文件,编辑文件内容如下
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
include fastcgi_params;
}
}
生成容器并链接phpsudo docker run --name nginx -p 80:80 -d -v /http/htdocs:/usr/share/nginx/html -v /http/nginx/conf:/etc/nginx/conf -v /http/nginx/conf.d:/etc/nginx/conf.d -v /http/nginx/logs:/var/log/nginx --link php-fpm:php nginx:1.16.0
测试php是否可以运行
使用sudo touch /http/htdocs/index.php
创建文件,编辑文件内容如下
<?php
phpinfo();
nginx 配置PHP取消index.php
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name; include fastcgi_params; #fastcgi_param PATH_INFO $1; #include fastcgi.conf; } }
https配置:
server { listen 443 ssl; #配置HTTPS的默认访问端口号为443。此处如>果未配置HTTPS的默认访问端口,可能会造成Nginx无法启动。Nginx 1.15.0以上版本请使用listen 443 ssl代替listen 443和ssl on。 server_name 域名地址; #将www.baidu.com修改为您证书绑定的域名,例如:www.example.com。如果您购买>的是通配符域名证书,要修改为通配符域名,例如:*.aliyun.com。 index index.html index.htm index.php; root /usr/share/nginx/html; ssl_certificate /etc/nginx/cert/cn.pem; #将domain name.pem替换成您证书的文件名称。 ssl_certificate_key /etc/nginx/cert/key.key; #将domain name.key替换成您证书的密钥文件名称。 ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4; #使用此加密套件。 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #使用该协议进行配置>。 ssl_prefer_server_ciphers on; location / { root /usr/share/nginx/html; index index.html index.htm index.php; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } location /nginx_status { stub_status on; access_log off; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } location ~ \.php$ { fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; #fastcgi_param PATH_INFO $1; #include fastcgi.conf; } }