GVKun编程网logo

php+nginx(php+nginx搭建站点,访问超时)

20

对于php+nginx感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解php+nginx搭建站点,访问超时,并且为您提供关于nginx优化突破十万并发nginxapachenginxphpn

对于php+nginx感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解php+nginx搭建站点,访问超时,并且为您提供关于nginx 优化突破十万并发 nginx apache nginx php nginx rewrite、NGINX 使用 nginx apache nginx php nginx rewrite、Nginx 多个版本都适用的伪静态配置 nginx apache nginx php nginx rewrite、nginx 多个站点配置 nginx apache nginx php nginx rewrite的宝贵知识。

本文目录一览:

php+nginx(php+nginx搭建站点,访问超时)

php+nginx(php+nginx搭建站点,访问超时)

ctf题目制作手册

 

一、制作题目

 

制作ctf题目前置条件:CentOS7,需要安装有docker服务

 

制作test1压缩包下的题目1:

 

1、明确题目要求,题目要求如下:

 

 

 

2、docker hub寻找合适的镜像:

(注意:寻找镜像时,不找无run启动命令的镜像)

无特殊要求,开始制作镜像。

首先根据题目要求从docker hub上寻找对应的镜像,该题目需要PHP镜像,需要PHP运行服务器,一般而言使用apache。

如图所示镜像是根据寻找找到的可用镜像

 

 

 

 

 

 

 

3、docker服务器下载镜像

如图所示,通过docker pull命令下载镜像

 

 

 

 

 

 

4、查看镜像 docker images

 

 

 

 

 

5、启动镜像 docker run -tid 镜像名:版本号(如果TAG为latest,则不用加版本号)

 

 

 

 

6、查找镜像对应的端口 docker ps

 

 

 

 

7、根据镜像对应的端口启动镜像

docker run -tid -p XX:XX 镜像名:版本号

(前边的XX代表虚拟机的端口,后面的XX代表容器的端口,容器的端口是通过刚刚找到的)

 

 

 

 

8、无特殊题目制作要求的情况下,将题目文件上传到对应的docker容器中

分三步进行,第一步:将题目文件上传到linux服务器中

 

 

 

 

第二步:找到docker容器进入的目录位置:

docker exec -it 容器id /bin/bash

(默认进入容器内部的命令为/bin/bash或者是/bin/sh)

然后pwd查看当前路径

 

 

 

 

第三步:将linux文件上传到docker容器对应的目录中:

docker cp 文件名 容器id:容器目录

 

 

 

 

9、打开浏览器访问

ip地址加端口(linux服务器ip+启动命令设置的linux虚拟机端口)

 

 

 

发现文件乱码如何解决

 

 

 

 

10、解决文件乱码问题:

分以下几步:

第一步,进入docker容器内部,删除docker 容器文件

 

 

 

第二步,删除宿主机上的文件

 

 

 

第三步,创建一个新文件,直接复制题目内容到新文件中,退出保存

 

 

 

 

 

 

第四步:将文件上传至docker 容器内部(和第8条第三步一样)

docker cp 文件名 容器id:容器目录

 

 

 

第五步:浏览器访问

 

 

 

 

 

11、把容器做成镜像,

docker commit 容器id 镜像名称

 

 

 

 

12、将镜像打成tar包

docker save -o XX.tar 镜像名:版本号

(XX为打包出来的文件名)

题目制作成功,tar包可用

 

13、tar包加载为镜像

下次使用时:将tar文件上传至服务器,加载镜像即可

docker load --input XXX.tar

 

二:CTF web题目权限问题

1. 根据制作的题目镜像启动容器

docker run -tid --name {container_name} -p {host_port}:{container_port} {image_id}/{image_name}:{tag}

 

 

 

 

2. 进入容器内部查看权限

docker exec -it {container_id} /bin/bash

 

 

 

 

 

3. 查看当前用户的权限

ps -a

 

 

 

Nginx和PHP-fpm的主进程(master process)为root用户权限;下方的Nginx权限为Nginx用户的权限,PHP-fpm权限为root用户的权限。当PHP进程的权限为root用户时,做题的人可以通过该权限直接对题目本身(容器)进行随意破坏,这样不行,需要修改PHP普通用户的权限。

 

4. 修改用户权限

cd /usr/local/etc

ls

vi PHP-fpm.conf

 

 

 

 

 

 

 

 

将文件内容修改为以下图片所示,修改user=root为user=www-data,修改listen.owner=root为listen.owner=www-data。

 

 

 

ps -a查看权限,配置完成之后,查看配置并未生效,需要对PHP重启使配置生效

 

 

 

supervisorctl status查看docker容器当前运行的应用

 

supervisorctl stop PHP 停止

supervisorctl start PHP 开启

效果等同于重启

supervisorctl restart PHP 重启

 

 

 

 

再次通过ps -a查看当前进程权限

 

 

 

用户权限已经改好了

 

 

5. 修改上传文件权限

在通过docker exec -it {container_id} /bin/bash进入容器内部的默认路径下执行

ls

mkdir upload

ls -al

新建的upload文件夹的权限为root:root(权限为root:root时,普通用户无法对文件夹进行写入,没有root权限,需要修改为普通用户也能访问)

chown [-R] 账号名称:用户组名称 文件或目录

chown www-data:www-data upload/

ls -al 查看权限的时候能看到upload文件夹权限用户以及用户组都变成了www-data www-data

 

 

 

用户上传文件夹权限已经修改完毕,可以让用户上传文件。

 

6. 把容器做成镜像

docker commit {container_id} {image_name}:{tag}

 

 

 

 

7. 将镜像打成tar包

docker save -o XX.tar {image_name}:{tag}

 

 

 

 

8. tar包加载为镜像

下次使用时:将tar文件上传至服务器,加载镜像即可

docker load --input XXX.tar

 

nginx 优化突破十万并发 nginx apache nginx php nginx rewrite

nginx 优化突破十万并发 nginx apache nginx php nginx rewrite

NGINX 使用 nginx apache nginx php nginx rewrite

NGINX 使用 nginx apache nginx php nginx rewrite

Nginx 多个版本都适用的伪静态配置 nginx apache nginx php nginx rewrite

Nginx 多个版本都适用的伪静态配置 nginx apache nginx php nginx rewrite

nginx 多个站点配置 nginx apache nginx php nginx rewrite

nginx 多个站点配置 nginx apache nginx php nginx rewrite

服务器地址:192.168.1.231

域名:test1.com 目录:/www/test1.com

域名:test2.com 目录:/www/test2.com

该配置思路

把2个站点 test1.com, test2.com 放到 nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件 test1.com.conf,test2.com.conf, 并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx

实际操作:

[root@localhost ~]# mkdir /www/test1.com
[root@localhost ~]# mkdir /www/test2.com
[root@localhost ~]# cd /etc/nginx/
[root@localhost nginx]# mkdir vhosts
[root@localhost nginx]# cd vhosts/
[root@localhost vhosts]# vi test1.com.conf 
#增加以下内容
server {
        listen  80;
        server_name  test1.com www.test1.com;
        access_log  /www/access_test1.log  main;
        location / {
            root   /www/test1.com;
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.html;
            fastcgi_param  SCRIPT_FILENAME  /www/test1.com/$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~ /.ht {
            deny  all;
        }
}
[root@localhost vhosts]# vi test2.com.conf 
#增加以下内容
server {
        listen  80;
        server_name  test2.com www.test2.com;

        access_log  /www/access_test2.log  main;

        location / {
            root   /www/test2.com;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.html;
            fastcgi_param  SCRIPT_FILENAME  /www/test2.com/$fastcgi_script_name;
            include        fastcgi_params;
        }

        location ~ /.ht {
            deny  all;
        }
}
登录后复制

修改nginx.conf

备份配置文件

立即学习“PHP免费学习笔记(深入)”;


[root@localhost ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf20160425
[root@localhost ~]# vi /etc/nginx/nginx.conf.
#修改成以下内容
user  nginx;
worker_processes  1;

# main server error log
error_log       /var/log/nginx/error.log ;
pid     /var/run/nginx.pid;
events {
        worker_connections  1024;
}
# main server config
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"'';
        sendfile        on;
        #tcp_nopush     on;
        #keepalive_timeout  0;
        keepalive_timeout  65;
        gzip  on;
        server {
                listen         80;
                server_name     _;
                access_log      /var/log/nginx/access.log main;
                server_name_in_redirect  off;
                location / {
                        root  /usr/share/nginx/html;
                        index index.html;
                }
        }
    # 这一行是加载上面的配置文件
    include /etc/nginx/vhosts/*;
}

重起nginx服务
[root@localhost ~]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@localhost ~]# 
登录后复制

下面我们进行测试是否成功

将nginx默认页面/usr/html/index.html 分别拷备到/www/test1.com和/www/test2.com里面

然后将index.html里面的内容分别改成test1.com和test2.com

测试机为windowns

修改host文件

# localhost name resolution is handled within DNS itself.

#    127.0.0.1       localhost

#    ::1             localhost

192.168.1.231    www.test1.com

192.168.1.231    www.test2.com

在该服务器上分别打开www.test1.com

test1.com

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Commercial support is available at nginx.com.

Thank you for using nginx.

在该服务器上分别打开www.test2.com

test2.com

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Commercial support is available at nginx.com.

Thank you for using nginx.

测试成功!!!!!


以上就介绍了nginx 多个站点配置,包括了nginx方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

我们今天的关于php+nginxphp+nginx搭建站点,访问超时的分享就到这里,谢谢您的阅读,如果想了解更多关于nginx 优化突破十万并发 nginx apache nginx php nginx rewrite、NGINX 使用 nginx apache nginx php nginx rewrite、Nginx 多个版本都适用的伪静态配置 nginx apache nginx php nginx rewrite、nginx 多个站点配置 nginx apache nginx php nginx rewrite的相关信息,可以在本站进行搜索。

本文标签: