1、启动nginx/usr/local/nginx/sbin/nginx -s reload 重新读取配置文件出错
使用默认的nginx.conf启动项目
[root@58a68b2af36c sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@58a68b2af36c sbin]# ./nginx -s reload
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
[root@localhost nginx]# cd logs
[root@localhost logs]# ls
access.log error.log nginx-access.log nginx_error.log
# 果然没有/usr/local/nginx/logs/nginx.pid 文件
[root@58a68b2af36c sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf
2、解决docker交互式运行容器不能使用 ll 命令
[root@58a68b2af36c php]# echo "alias ll='ls $LS_OPTIONS -l'" >> ~/.bashrc && source ~/.bashrc
[root@58a68b2af36c php]# vim ~/.bashrc
3、解决php-fpm启动报错
[root@58a68b2af36c sbin]# ./php-fpm
[01-Jan-2020 20:48:48] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
[01-Jan-2020 20:48:48] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[01-Jan-2020 20:48:48] ERROR: FPM initialization failed
解决方法:
[root@58a68b2af36c sbin]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@58a68b2af36c sbin]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
[root@58a68b2af36c sbin]# ./php-fpm
4、解决nginx+php下访问不了php文件
2020/01/01 20:55:08 [error] 43#0: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 223.74.101.69, server: localhost, request: "GET /i.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "121.40.191.171:8080"
- 配置问题 $document_root
location ~ \.php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
- 文件访问权限
ls
使用Dockerfile构建nginx+php环境
FROM centos
MAINTAINER mgk<meigkun@163.com>
ENV TZ "Asia/Shanghai"
ENV MYPATH /www/html
WORKDIR $MYPATH
VOLUME ["/www"]
# 安装
RUN yum install -y curl wget tar bzip2 unzip vim-enhanced passwd sudo yum-utils hostname net-tools rsync man && \
yum install -y gcc gcc-c++ openssl openssl-devel libxml2-devel pcre-devel pcre && \
yum install -y libxml2-devel bzip2 bzip2-devel make automake cmake patch libpng-devel libjpeg-devel && \
yum install -y curl libcurl libcurl-devel libXpm-devel freetype freetype-devel postgresql-devel libxslt-devel && \
yum clean all
#不知道这个要不要
RUN groupadd www
RUN useradd -r www -g www
# nginx
COPY ./nginx-1.16.1.tar.gz /soft/
RUN cd /soft && tar -zxvf nginx-1.16.1.tar.gz && cd nginx-1.16.1 &&\
./configure --user=www --group=www --prefix=/usr/local/nginx \
--with-http_stub_status_module --with-http_ssl_module \
--with-http_gzip_static_module --with-pcre && \
make && make install
# php
COPY ./php-7.2.25.tar.gz /soft/
RUN cd /soft && tar -zxvf php-7.2.25.tar.gz && cd php-7.2.25 &&\
./configure --prefix=/usr/local/php --with-pdo-pgsql \
--with-zlib-dir --with-freetype-dir --enable-mbstring \
--with-libxml-dir=/usr --enable-soap --enable-calendar \
--with-curl --with-mcrypt=/usr/local/bin/libmcrypt \
--with-gd --with-pgsql --disable-rpath --enable-inline-optimization \
--with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm \
--enable-pcntl --enable-mbregex --enable-exif \
--enable-bcmath --with-mhash --enable-zip --with-pcre-regex \
--with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --enable-gd-native-ttf \
--with-openssl --with-fpm-user=www --with-fpm-group=www \
--enable-ftp --with-gettext --with-xmlrpc --with-xsl --enable-fpm \
--with-iconv --with-xpm-dir=/usr/bin --enable-pdo --with-mysql=mysqlnd && make && make install
# 配置PHP文件
RUN cp /soft/php-7.2.25/php.ini-production /usr/local/php/lib/php.ini && \
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && \
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/wwww.conf &&\
echo 'export PHP_HOME=/usr/local/php' >> /etc/profile && echo 'export PATH=$PATH:$PHP_HOME/bin' >> /etc/profile && \
source /etc/profile
# 解决交互式启动docker无法使用ll命令
RUN echo "alias ll='ls $LS_OPTIONS -l'" >> ~/.bashrc && source ~/.bashrc
# mysql 有点不成功,不知道docker内部怎么启动mysql,也用不了service命令
# COPY ./mysql-community-server-5.7.28-1.el7.x86_64.rpm /soft/
# COPY ./mysql-community-client-5.7.28-1.el7.x86_64.rpm /soft/
# RUN cd /soft && rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm --force --nodeps && \
# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm --force --nodeps
#EXPOSE 映射端口
EXPOSE 80 9000
#CMD 运行以下命令
CMD /bin/bash
运行之后修改nginx配置文件并启动、php启动,测试就可以。
网友评论