nginx安装
实验环境:kaliLinux
apt-get install nginx //安装nginxservice nginx start //启动nginxservice nginx stop //停止nginx
然后启动了就可以访问127.0.0.1了
此时所有的nginx配置文件都在 /etc/nginx下

你需要添加新配置选项的地方位于 sites-enabled 文件夹。如果你打开这个文件夹,你会发现一个名为 default 的txt文档,打开后你就会找到nginx的配置选项以及 “welcome to nginx”欢迎选项的代码。
内容
server {listen 80 default_server;listen [::]:80 default_server;# SSL configuration## listen 443 ssl default_server;# listen [::]:443 ssl default_server;## Note: You should disable gzip for SSL traffic.# See: https://bugs.debian.org/773332## Read up on ssl_ciphers to ensure a secure configuration.# See: https://bugs.debian.org/765782## Self signed certs generated by the ssl-cert package# Don't use them in a production server!## include snippets/snakeoil.conf;root /var/www/html;# Add index.php to the list if you are using PHPindex index.html index.htm index.nginx-debian.html;server_name _;location / {# First attempt to serve request as file, then# as directory, then fall back to displaying a 404.try_files $uri $uri/ =404;}# pass PHP scripts to FastCGI server##location ~ \.php$ {# include snippets/fastcgi-php.conf;## # With php-fpm (or other unix sockets):# fastcgi_pass unix:/run/php/php7.4-fpm.sock;# # With php-cgi (or other tcp sockets):# fastcgi_pass 127.0.0.1:9000;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# Virtual Host configuration for example.com## You can move that to a different file under sites-available/ and symlink that# to sites-enabled/ to enable it.##server {# listen 80;# listen [::]:80;## server_name example.com;## root /var/www/example.com;# index index.html;## location / {# try_files $uri $uri/ =404;# }#}
接下来我们开始建立属于我们自己的配置文件用于显示一个页面。在sites-enabled目录下新建一个空白文件并命名为 test,用你自己喜欢的文本编辑器进行编辑。
只有在 sites-enabled 目录下的配置文件才能够真正被用户访问。但是你同样可以将文件放在 sites-available 目录下用来存档或者生成链接。

同样生成链接
ln -s /etc/nginx/sites-available/test /etc/nginx/sites-enabled/test

在sites-available 下编辑
配置静态服务器
Nginx配置文件有自己的格式,好消息是文件的格式相当简单,看起来特别像CSS文件,先指定变量名,然后在花括号内编写指令。最顶层是 server ,代码为:
server {}
声明服务器监听的端口号。如果你了解rails,你一定知道本地服务器的默认端口是3000. Roots运行在1111端口。SSL在443端口。互联网的默认端口是80,因此在url中未定义端口的话一般默认为80。因为你很有可能是去运行一个线上的服务器,因此最好定义成80端口。代码如下:
server {listen 80;}
注意默认端口严格来讲不是必要的,但是为了能够保证你对整个流程足够了解最好加上。完成了第一步,我们进入下一步server_name.
server_name主要用来匹配url地址。任意请求通过nginx时,它会查看url并寻找 server_name 片段。如果你的站点地址为 http://xvfeng.me, 那么你的 server_name 应当也为 xvfeng.me . 如果你在域名解析时使用了A记录并通过服务器指向 http://snargles.com , 你可以添加另外一个 server 代码,将 server_name 指向 snargles.com, 这段代码就会匹配来自于这个域名的请求。
这个特性非常强大。这意味着你可以在单个nginx配置文件里托管无数个站点,甚至包括不同域名的网站。你需要做的只是将设置A记录并指向虚拟机所在的IP, 之后设置其他的nginx服务器配置。
针对 server_name 还有两点值得关注。首先是你可以设置子域名。如果你想匹配http://test.example.com ,设置相当简单,甚至还可以指向一个完全不同的应用。第二点,你可以使用通配符, 即 * 或者正则来匹配路由。这个功能绝对强大。下面我们简单的配置一下server_name到example.com .
server {listen 80;server_name example.com;}
Nice.接下来再加一些配置就可以让服务器运转了。
这个是托管静态站点最关键的部分。如果你只是想用它来托管一些html和css文件,root部分要定义的就是这些文件存放的路径。我喜欢把文件放在 /var/www 目录下,因此我们在这里建立一个文件夹。使用 mkdir 创建 /var/www/example 目录,建立一个空白的 index.html 文件,随便添加一些段落输出hello world之类的内容。代码如下:
server {listen 80;server_name example.com;root /var/www/example;}
基本变量设置完毕,下一步配置路由。
Location接受两个参数,一个字符串或者正则和一段代码。字符串或者正则用于匹配某个特定目录。如果你想让用户在访问 example.com/whaterver 时访问某个特定页面,你需要将 whatever 设置为uri地址。在这里我们只需要访问root目录,因此只需要加上 / 即可,内容暂时为空,后面再做解释。
server {listen 80;server_name example.com;root /var/www/example;location / {}}
第一参数可以有很多种写法,你可以参考上面给出的链接。在以上区块内,我们需要路由指向结果页面。注意 / 会匹配所有的url地址,因为在这里它被解释为一个正则。如果你只想匹配某个准确的字符串,只需要在前面加上一个等号,写法如下:
location = / { ... }
现在我们需要完成之前的代码。我们可以在区块内添加另外一段指令,用于加载名为 try_files 的文件。Try fiels接受了一组文件名或者正则,用于在根目录下查找,并会加载查找到的第一个结果。对于我们的静态服务器来讲,我们希望找到一个在 / 之后紧跟着whatever的文件,例如 whatever.html. 如果在斜线后面没有任何内容,则会寻找 index.html. 在上面给出的文档链接中你可以找到更多的关于如何设置该选项的吸纳关系介绍,这里我们只写一些简单的配置:
server {listen 80;server_name example.com;root /var/www/example;location / {try_files $uri $uri/ /index.html;}}
你可能会奇怪上面的 $url 是从哪里来的?其实是nginx所提供的。每次有请求时,nginx会生成一系列变量,这些变量存储了请求的相关信息。这里的uri就是我们将要了解的内容之一。
- 来自
http://example.com的请求进入。 - nginx找到server片段代码,其中
server_name为example.com,并使用它来处理请求 - nginx匹配任意请求。因为这里的
/会匹配根域名下的任意内容。 - 在匹配到的location代码中,nginx开始试图加载一个文件。首先寻找一个未命名的文件,因为这里的uri匹配的就是没有名称的文件,所以无法找到。接着开始查找未命名的目录,结果还是找不到。最后开始查找并加载根目录下
/index.html。
接下来想象一下如果你添加一个名为 test.html 的文件到根目录下并访问 http://example.com/test.html.自己试一下你就知道了。
你可以任意的去尝试改变这里的配置环境。例如,在carrot.is这个网站里,但用户访问某个文件并且没有加上 .html 后缀时,try_files同样会查找 $uri.html 并匹配相应结果。因此在你访问http://carrot.is.about 和 http://carrot.is/about.html 时你会得到相同的文件。你可以充分发挥你的想象力去设置你的配置文件。
启动服务
总结一下我们所做的事情。首先添加了 server 选项,在nginx运行时,会查找 /etc/sites-enabled 目录下的所有配置文件用于显示对应内容。但是请等一下,你可能无法马上得到结果-因为nginx并不知道你所作的这些改动。为了让nginx真正读取新配置文件,你需要重启服务器,运行以下命令:
service nginx reload
注意:这里的
service命令实际上是调用了配置文件里内容,这些都在使用apt时被生成。这里调用的实际上是/etc/init.d/nginx reload
记得改一下hosts文件


php-fpm安装

sudo apt-get -y install php7.4sudo apt-get -y install php7.4-fpm

打开 /etc/php/7.4/fpm/pool.d/www.conf 文件找到如下位置,注释掉第一行并添加第二行:

注意这里如果设置监听为0.0.0.0:9000就在产生php-fpm未授权访问漏洞,此时攻击者可以直接与9000端口上的php-fpm进行通信,进而可以实现任意代码执行。
我们这里设置成0.0.0.0:9000
打开nginx的配置文件 /etc/nginx/sites-available/test 修改相应部分的配置
server {listen 80; #监听80端口,接收http请求server_name www.example.com; #就是网站地址root /var/www/html; # 准备存放代码工程的路径#路由到网站根目录www.example.com时候的处理location / {index index.php; #跳转到www.example.com/index.phpautoindex on;}#当请求网站下php文件的时候,反向代理到php-fpmlocation ~ \.php$ {fastcgi_split_path_info ^(.+\.php)(/.+)$;fastcgi_pass 0.0.0.0:9000;#nginx fastcgi进程监听的IP地址和端口#fastcgi_pass unix:/run/php/php7.4-fpm.sock;fastcgi_index index.php;include fastcgi_params;}}

启动php-fpm 如果页面为空,查看这篇文章解决

安装phpxdebug
apt-get install php-xdebugfind / -name "xdebug.so"
编辑vim /etc/php/7.4/fpm/php.ini
如果是xdebug2
[xdebug]zend_extension="/usr/lib/php/20190902/xdebug.so"xdebug.remote_enable=1xdebug.remote_autostart=1xdebug.remote_host=192.168.75.1xdebug.remote_port=10000
如果是xdebug3
[xdebug]zend_extension = "/usr/lib/php/20190902/xdebug.so"xdebug.log = /usr/local/php/xdebug.logxdebug.mode = debugxdebug.start_with_request = yesxdebug.client_port = 10000xdebug.client_host = 192.168.75.1xdebug.remote_handler = dbgpxdebug.idekey = PHPSTORMxdebug.cli_color = 2xdebug.var_display_max_depth = 15xdebug.var_display_max_data = 2048
注意 host是phpstorm所在机器的ip
重启php-fpm
pkill php-fpm/usr/sbin/php-fpm7.4

添加调试端口

添加服务器,主机是靶机ip 然后路径映射一定要正确

然后添加IDE键 PHPSTORM

添加好后点监听和调试

然后访问页面即可进入断点

