提交 01e753b9 authored 作者: chenhuan's avatar chenhuan

fix

上级 9978a6c7
name: build
on: [push, pull_request]
jobs:
docker-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Hadolint
uses: hadolint/hadolint-action@v2.1.0
sh-checker:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Run sh-checker
uses: luizm/action-sh-checker@master
env:
SHFMT_OPTS: -i 4 -d
build:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: ["7.4", "8.0", "8.1"]
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Build Docker image
run: docker build -t nginx-php:${{ matrix.php_version }} --build-arg PHP_VERSION=${{ matrix.php_version }} .
# TODO: Investigate why I get the error `docker: 'scan' is not a docker command.` on GitHub Actions and re-enable this when possible
# We only get 10 free scans a month, hopefully we never use that up or this step will fail
# - name: Docker Scan
# run: docker scan nginx-php:${{ matrix.php_version }}
- name: Run Docker image
run: docker run -d --name nginx-php -t nginx-php:${{ matrix.php_version }}
- name: Test image is running
run: docker ps | grep -q nginx-php
- name: Test nginx config inside container
run: |
sleep 10
docker exec -t nginx-php nginx -T
name: latest
on:
push:
branches:
- main
jobs:
latest:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Install buildx
uses: docker/setup-buildx-action@v1
- name: Sign into Docker
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Build latest Docker image and push to Docker Hub
run: docker buildx build --push -t justintime50/nginx-php --platform linux/amd64,linux/arm/v7,linux/arm64 .
name: release
on:
push:
tags:
- "*"
jobs:
release:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: ["7.4", "8.0", "8.1"]
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Install buildx
uses: docker/setup-buildx-action@v1
- name: Sign into Docker
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Build Docker image and push to Docker Hub
run: docker buildx build --push -t justintime50/nginx-php:${{ matrix.php_version }}-${GITHUB_REF##*/} --build-arg PHP_VERSION=${{ matrix.php_version }} --platform linux/amd64,linux/arm/v7,linux/arm64 .
# CHANGELOG\
## 11 (2022-04-24)
- Corrects port exposure back to ports 80 and 443 as intended externally
## 10 (2022-04-23)
- Container now runs as `www-data` instead of `root` dramatically increasing security
- Container now exposes ports `8080` and `8443` instead of `80` and `443`
## 9 (2021-11-30)
- Adds PHP 8.1 support
## 8 (2021-10-12)
- Adds build architectures for linux/amd64 (eg: Intel), linux/arm/v7 (eg: Raspberry Pi), linux/arm64 (eg: M1 Macs)
## 7 (2021-07-23)
- Changes nginx config path from `/etc/nginx/conf.d/*.conf` to `/etc/nginx/http.d/*.conf` as this was altered in Alpine 3.14/15
- Pins dependencies to their major versions
- Changes default location from `/var/www/html` to `/var/www/html/public`, this will allow Laravel applications to use the same nginx config without the need to change anything.
- Changes nginx landing page to PHP Info
- Improved OPcache performance by allowing more memory
- Remove build cache when finished to reduce image size
- Moved opcache config from the Dockerfile to a separate `ini` file, enabled JIT compiling
- Expire static asset caching after 30 days in nginx config
- Deny access to non-site or public assets in nginx config
- Turns off nginx version info on publicly accessible pages
- Due to Docker autobuilds becoming a paid service, the `latest` tag will now be built via GitHub Actions on any push to the main branch.
- Updates various pieces of documentation
## 6 (2021-02-27)
- Removes `server_name` from nginx.conf as it's not needed
## 5 (2021-02-08)
- Adds `Composer` to the image out of the box
- Set explicit shell
## 4 (2021-02-06)
- Dropped support for PHP 7.0 - 7.3 due to GD changes that cannot build properly under those versions
- Switched from Travis CI to GitHub Actions
- Adopted new release workflow where each change simply iterates the version number since we provide images for various PHP versions
## 3 (2020-12-08)
- Added PHP 8.0 support
- Updated documentation
## 2 (2020)
- Added backwards support for PHP 7.0 and 7.1
## 1 (2020)
- Initial release
FROM php:7.4.30-fpm-bullseye
WORKDIR /srv/www/
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN mv /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
RUN install-php-extensions \
bcmath \
exif \
gd \
gmp \
opcache \
pdo_mysql \
zip \
redis \
mongodb \
&& rm /usr/local/bin/install-php-extensions
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
EXPOSE 9000
CMD ["php-fpm"]
MIT License
Copyright (c) 2019 Justin Hammond
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<div align="center">
# Nginx/PHP-FPM Docker Image
A lightweight combined Nginx/PHP-FPM Docker image.
[![Build Status](https://github.com/Justintime50/nginx-php-docker/workflows/build/badge.svg)](https://github.com/Justintime50/nginx-php-docker/actions)
[![Image Size](https://img.shields.io/docker/image-size/justintime50/nginx-php)](https://hub.docker.com/repository/docker/justintime50/nginx-php)
[![Docker Pulls](https://img.shields.io/docker/pulls/justintime50/nginx-php)](https://hub.docker.com/repository/docker/justintime50/nginx-php)
[![Licence](https://img.shields.io/github/license/justintime50/nginx-php-docker)](LICENSE)
</div>
## Features
The following features work out of the box without any configuration:
- `PHP-FPM/OPcache` for fast performance in the browser and on the CLI
- `Nginx` serves as the web host and reverse proxy
- `msmtp` is installed and configured (see `config/msmtprc`) to send mail locally for testing via apps like `Mailcatcher` which will work out of the box (if Mailcatcher container is titled `mailcatcher`)
- `mysql_pdo` is installed as the driver for database connections
- `gd` is installed for image processing
- `zip` is installed for items that may need that
- `composer` is installed and ready to use to setup all your dependencies
## Platforms
This image offers platform support for the following architectures starting from image version `8`:
- linux/amd64
- linux/arm/v7
- linux/arm64
## Install
```bash
# Dockerfile
FROM: justintime50/nginx-php:latest
# docker-compose
image: justintime50/nginx-php:latest
```
## Usage
**Vanilla PHP and HTML**
Place your `PHP` or `HTML` site files into `/var/www/html/public` inside the container to get started with this image. This can be achieved by using a volume in a `docker-compose` file or by copying them over in a `Dockerfile`. If you are using HTML instead of PHP, ensure you remove the `index.php` file so that your `index.html` file can take priority.
**Laravel**
Place the root of your laravel project in `/var/www/html` so that the `public` folder of laravel lines up with the directory served by this nginx image (see `examples/laravel` for more details).
Want to give this image a spin? Simply run the following:
```bash
docker compose up -d
```
Once the container spins up, navigate to `http://localhost:8888` in a browser.
## Docker Tags
Tags for this image follow the syntax of `PHP_VERSION-IMAGE_VERSION`; for instance, a valid tag would be `7.4-9` signifying to use PHP v7.4 and the 9th version of this image (nginx config, Dockerfile, etc).
**PHP Versions**
- `8.1` - uses the latest release on the PHP 8.1 Alpine track. (Starting with image version `9`)
- `8.0` - uses the latest release on the PHP 8.0 Alpine track.
- `7.4` - uses the latest release on the PHP 7.4 Alpine track.
**Image Versions (see CHANGELOG for more details)**
- `10`
- `9`
- `8`
- `7`
**Standalone Tags**
- `latest` - uses the latest release of this image with all defaults.
- `dev` - the testing branch for this image. Do not use this tag in production.
## Development
**Note:** Alpine Linux does not keep old versions of packages. This image pins to the relative major version to try staying flexibile. Future builds may need to be altered if packages are no longer offered.
```bash
# Test nginx configuration
nginx -T
```
**Releasing**
When releasing this project, cut a new GitHub tag/release that simply iterates the number (eg: 4, 5, 6...). We won't use semver here for simplicity when tagging images.
### Building New Versions
This image supports swapping in the version number of PHP with a value from the official `PHP-FPM Alpine` [tag list](https://hub.docker.com/_/php).
**Automated Builds**
GitHub Actions will automatically build and push supported tags to Docker Hub on each new release. Additionally GitHub Actions will automatically build the `latest` tag on any push to the main branch. It is highly recommended that you use a versioned release of this image to avoid any transient changes introduced in any given `latest` build.
**Manual Builds**
```bash
docker build -t justintime50/nginx-php:8.0-7 --build-arg PHP_VERSION=8.0 .
sudo docker push justintime50/nginx-php:8.0-7
```
## MSMTPRC Config for Mail Server ##
# This config file is built to work with a Mailcatcher Docker container out of the box
# Setup general config
host mailcatcher
port 1025
#auth on
tls off
tls_starttls off
#tls_trust_file /etc/ssl/certs/ca-certificates.crt
auto_from on # Construct envelope-from addresses of the form "user@oursite.example"
maildomain localhost
logfile /var/log/msmtp.log
## Set a default account
#account default : gmail
## BELOW IS A SAMPLE FOR RELAYING USING A GMAIL ACCOUNT (UNTESTED)
## Gmail account template
#account gmail
#host smtp.gmail.com
#port 587
#from $GMAIL_USER
#user $GMAIL_USER
#password $GMAIL_PASS
## BELOW IS THE LOCAL TEST ACCOUNT CONFIGURED TO USE WITH APPS SUCH AS MAILCATCHER
## An email address to use for local testing
account test
from test
user test@test.com
password test
server {
listen 80;
index index.php index.html index;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
client_max_body_size 5m;
client_body_buffer_size 128k;
server_tokens off;
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 30d;
}
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
# Configure OPcache for FPM PHP
opcache.enable_cli=1
# Performance config
opcache.memory_consumption=196
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=20000
opcache.max_wasted_percentage=10
opcache.revalidate_freq=2 # we compromise some performance gains here by allowing cache-invalidation for dev projects
opcache.fast_shutdown=1
# Enable JIT compiling
opcache.jit=tracing
opcache.jit_buffer_size=50M
services:
nginx-php:
container_name: "nginx-php"
build: .
ports:
- "8888:80"
FROM justintime50/nginx-php:8.1-11
COPY --chown=www-data:www-data ./src /var/www/html
RUN composer install --no-ansi --no-interaction --no-scripts --no-plugins --no-progress --prefer-dist \
# Setup Laravel
&& chmod -R 755 storage bootstrap/cache \
&& php artisan storage:link \
&& php artisan optimize:clear
services:
my-project:
volumes:
- ./src/storage:/var/www/html/storage
#!/bin/sh
main() {
echo "Starting up nginx-php..."
nginx
php-fpm
}
main
#user nobody;
worker_processes auto;
worker_rlimit_nofile 51200;
#error_log logs/error.log;
#error_log logs/error.log notice;
......@@ -9,7 +10,11 @@ worker_processes auto;
events {
worker_connections 1024;
use epoll;
worker_connections 51200;
multi_accept on;
}
......@@ -17,54 +22,43 @@ http {
include 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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 120s;
client_max_body_size 100m;
server_tokens off;
#gzip on;
# Disabled due to license
# geoip2 /etc/nginx/GeoLite2-Country.mmdb {
# auto_reload 1h;
#
# $geoip2_metadata_country_build metadata build_epoch;
#
# # populate the country
# $geoip2_data_country_code source=$remote_addr country iso_code;
# $geoip2_data_country_name source=$remote_addr country names en;
#
# # populate the continent
# $geoip2_data_continent_code source=$remote_addr continent code;
# $geoip2_data_continent_name source=$remote_addr continent names en;
# }
#
# geoip2 /etc/nginx/GeoLite2-City.mmdb {
# auto_reload 1h;
#
# # City name itself
# $geoip2_data_city_name source=$remote_addr city names en;
#
# # Postal code will be an approximation, probably the first one in the list that covers an area
# $geoip2_data_postal_code source=$remote_addr postal code;
#
# # State in code and long form
# $geoip2_data_state_code source=$remote_addr subdivisions 0 iso_code;
# $geoip2_data_state_name source=$remote_addr subdivisions 0 names en;
#
# # Lat and Lng
# $geoip2_data_latitude source=$remote_addr location latitude;
# $geoip2_data_longitude source=$remote_addr location longitude;
# }
server_names_hash_bucket_size 512;
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 5;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
include /etc/nginx/sites-enabled/*;
}
......
FROM php:7.4.30-fpm-bullseye
WORKDIR /var/www/html
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN mv /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
RUN echo "deb http://mirrors.aliyun.com/debian bullseye main contrib non-free" > /etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian bullseye main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://mirrors.aliyun.com/debian bullseye-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian bullseye-updates main contrib non-free" >> /etc/apt/sources.list \
RUN install-php-extensions \
bcmath \
exif \
gd \
gmp \
opcache \
pdo_mysql \
zip \
redis \
mongodb \
&& rm /usr/local/bin/install-php-extensions
ADD index.php /var/www/html/
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
EXPOSE 9000
CMD ["php-fpm"]
<?php
echo phpinfo();
?>
\ No newline at end of file
WiredTiger
WiredTiger 10.0.0: (March 18, 2020)
WiredTiger version string
WiredTiger 10.0.0: (March 18, 2020)
WiredTiger version
major=10,minor=0,patch=0
file:WiredTiger.wt
access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=,cache_resident=false,checksum=uncompressed,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_key=,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=S,version=(major=1,minor=1),checkpoint=(WiredTigerCheckpoint.3236=(addr="018b81e48391aedd8c81e4cf483c838d81e41b91652c808080e2cfc0e21fc0",order=3236,time=1655547168,size=20480,newest_start_durable_ts=0,oldest_start_ts=0,oldest_start_txn=0,newest_stop_durable_ts=0,newest_stop_ts=-1,newest_stop_txn=-11,prepare=0,write_gen=9706)),checkpoint_backup_info=,checkpoint_lsn=(1,3745152)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论