Sign inSign up

hotxia/lnmp

By hotxia

Updated about 7 years ago

CentOS7 + Nginx-1.12.2+Php5.4

Image
0

817

hotxia/lnmp repository overview

启动命令

     [root@linux-node1 ~]# docker run -it -p 80:80 --name=my_nginx hotxia/lnmp supervisord 

制作nginx镜像

[root@linux-node1 ~]# docker run -it --name my_nginx centos bash
[root@8687ddd0afca /]# 

[root@8687ddd0afca ~]# yum install -y nginx
[root@8687ddd0afca ~]# yum install php-fpm -y
[root@8687ddd0afca ~]# yum install -y supervisor -y
	supervisor 配置文件 /etc/supervisord.conf
	[root@8687ddd0afca supervisord.d]# vim php_nginx.ini
	[supervisord]  启动模式以后台进程运行
	nodaemon=true
	 
	[program:nginx]  程序名为nginx
	command=/usr/sbin/nginx -g "daemon off;" 启动命令:以前台方式启动
	
	[program:phpfpm]
	command=/usr/sbin/php-fpm -F -c /etc/php.ini
	autostart = true   		自动启动
	startsecs = 3			启动3次,超过3次不再启动
	autorestart = true		自动重启
	startretries = 3		重启3次后,无法正常重启,不再重启
	user = root				以root用户方式启动
	redirect_stderr = false  日志重定向
	stdout_logfile_maxbytes = 50MB	定义日志大小
	stdout_logfile_backups = 20
	
	[root@8687ddd0afca supervisord.d]# vim php_nginx.ini
	[root@8687ddd0afca supervisord.d]# supervisord   前台方式运行
			
	验证启动进程
	[root@linux-node1 ~]# docker exec -it my_nginx bash
	[root@8687ddd0afca /]# 
	[root@8687ddd0afca /]# ps -ef
	UID         PID   PPID  C STIME TTY          TIME CMD
	root          1      0  0 Jul11 pts/0    00:00:00 bash
	root        703      1  0 09:40 pts/0    00:00:00 /usr/bin/python /usr/bin/supervisord
	root        706    703  0 09:40 pts/0    00:00:00 nginx: master process /usr/sbin/nginx -g 
	root        707    703  0 09:40 pts/0    00:00:00 php-fpm: master process (/etc/php-fpm.con
	nginx       708    706  0 09:40 pts/0    00:00:00 nginx: worker process
	nginx       709    706  0 09:40 pts/0    00:00:00 nginx: worker process
	apache      710    707  0 09:40 pts/0    00:00:00 php-fpm: pool www
	apache      711    707  0 09:40 pts/0    00:00:00 php-fpm: pool www
	apache      712    707  0 09:40 pts/0    00:00:00 php-fpm: pool www
	apache      713    707  0 09:40 pts/0    00:00:00 php-fpm: pool www
	apache      714    707  0 09:40 pts/0    00:00:00 php-fpm: pool www
	root        715      0  0 09:42 pts/1    00:00:00 bash
	root        734    715  0 09:42 pts/1    00:00:00 ps -ef

	[root@8687ddd0afca /]# ss -tnl
	State      Recv-Q Send-Q        Local Address:Port                       Peer Address:Port              
	LISTEN     0      128                       *:80                                    *:*                  
	LISTEN     0      128               127.0.0.1:9000                                  *:*                  
	LISTEN     0      128                      :::80                                   :::*         

	容器上传镜像
	[root@linux-node1 ~]# docker commit -m "nginx-1.12.2 php-5.4" my_nginx nignx:v1
	sha256:3e5e4a11b5f31881382ae4785243fc87cafba51dff0523de1132de571a4ed1f2

	[root@linux-node1 ~]# docker images
	REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
	nignx               v1                  3e5e4a11b5f3        26 seconds ago      571MB
	sebp/elk            latest              cd5e6e46d1a2        5 days ago          1.93GB
	nginx               latest              f68d6e55e065        10 days ago         109MB
	alpine              latest              4d90542f0623        3 weeks ago         5.58MB
	busybox             latest              e4db68de4ff2        3 weeks ago         1.22MB

	启动打包新的镜像
	[root@linux-node1 ~]# docker run -it -p 80:80 --name=nginx_v1 3e5e4a11b5f3 supervisord    #-p 映射端口
	/usr/lib/python2.7/site-packages/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
	  'Supervisord is running as root and it is searching '
	2019-07-12 09:51:45,258 CRIT Supervisor running as root (no user in config file)
	2019-07-12 09:51:45,259 WARN Included extra file "/etc/supervisord.d/php_nginx.ini" during parsing
	2019-07-12 09:51:45,276 INFO RPC interface 'supervisor' initialized
	2019-07-12 09:51:45,276 CRIT Server 'unix_http_server' running without any HTTP authentication checking
	2019-07-12 09:51:45,276 INFO supervisord started with pid 1
	2019-07-12 09:51:46,279 INFO spawned: 'nginx' with pid 8
	2019-07-12 09:51:46,281 INFO spawned: 'phpfpm' with pid 9
	2019-07-12 09:51:47,383 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
	2019-07-12 09:51:49,386 INFO success: phpfpm entered RUNNING state, process has stayed up for > than 3 seconds (startsecs)

	配置nginx+php
	[root@0643a7151a31 html]# vim /etc/nginx/nginx.conf

			location ~ [^/]\.php(/|$)
					{
						# comment try_files $uri =404; to enable pathinfo
						try_files $uri =404;
						fastcgi_pass  127.0.0.1:9000;
						fastcgi_index index.php;
						include fastcgi.conf;
						#include pathinfo.conf;
						set $real_script_name $fastcgi_script_name;
						if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
							set $real_script_name $1;
							set $path_info $2;
						}
						fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
						fastcgi_param SCRIPT_NAME $real_script_name;
						fastcgi_param PATH_INFO $path_info;
						fastcgi_param APPLICATION_ENV 'development';
					}

	检查nginx配置语法并启动nginx
	[root@0643a7151a31 html]# nginx -t
	nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
	nginx: configuration file /etc/nginx/nginx.conf test is successful
	[root@0643a7151a31 html]# nginx -s reload

	查看supervisor启动进程状态
	[root@0643a7151a31 html]# supervisorctl status
	nginx                            RUNNING   pid 8, uptime 0:09:36
	phpfpm                           RUNNING   pid 9, uptime 0:09:36

	访问验证
	[root@linux-node2 ~]# curl -I http://192.168.56.11/phpinfo.php
	HTTP/1.1 200 OK
	Server: nginx/1.12.2
	Date: Fri, 12 Jul 2019 02:06:25 GMT
	Content-Type: text/html
	Connection: keep-alive
	X-Powered-By: PHP/5.4.16

Tag summary

Content type

Image

Digest

Size

205.4 MB

Last updated

about 7 years ago

docker pull hotxia/lnmp