广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >ubuntu22.4配置nginx和php
  • 922
分享到

ubuntu22.4配置nginx和php

nginxphp 2023-09-22 09:09:52 922人浏览 八月长安
摘要

实验操作步骤 安装ngix 这里使用命令: sudo apt install Nginx 2.icestone@icestone-nb:~$ sudo apt install nginx3.[sudo

实验操作步骤

  1. 安装ngix
    这里使用命令:
    sudo apt install Nginx
2.icestone@icestone-nb:~$ sudo apt install nginx3.[sudo] icestone 的密码: 4.正在读取软件包列表... 完成5.正在分析软件包的依赖关系树... 完成6.正在读取状态信息... 完成                 7.将会同时安装下列软件:8.  libnginx-mod-Http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libnginx-mod-stream-geoip2 nginx-common nginx-core9.下列【新】软件包将被安装:10.  libnginx-mod-http-geoip2 libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libnginx-mod-stream-geoip2 nginx nginx-common nginx-core11.升级了 0 个软件包,新安装了 9 个软件包,要卸载 0 个软件包,有 2 个软件包未被升级。12.需要下载 696 kB 的归档。13.解压缩后会消耗 2,395 kB 的额外空间。14.您希望继续执行吗? [Y/n] Y2.调整防火墙:sudo ufw app list15.icestone@icestone-nb:~$ sudo ufw allow 'Nginx HTTP'16.规则已添加17.规则已添加 (v6)18.icestone@icestone-nb:~$ sudo ufw allow 'Nginx https'19.规则已添加20.规则已添加 (v6)21.icestone@icestone-nb:~$ sudo ufw allow 'Nginx Full'22.规则已添加23.规则已添加 (v6)

查看结果:
sudo ufw status

24.icestone@icestone-nb:~$ sudo ufw status25.状态: 激活26.27.至                          动作          来自28.-                          --          --29.                 ALLOW       Anywhere                  30.80/tcp                     ALLOW       Anywhere                  31.443/tcp                    ALLOW       Anywhere

success

检查WEB服务:
systemctl status nginx

32.icestone@icestone-nb:~$ systemctl status nginx33.● nginx.service - A high perfORMance web server and a reverse proxy server34.     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)35.     Active: active (running) since Thu 2022-11-10 23:07:21 CST; 1h 14min aGo36.       Docs: man:nginx(8)37.    Process: 21371 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)38.    Process: 21374 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

success
39. 访问;
http://localhost/
在这里插入图片描述

开启https:
40. 修改配置文件
这里由于使用的ubuntu22.04
修改 /etc/nginx/sites-available/default
添加:

41.# 下面是我自己写的配置:42.server{43. listen 443 ssl;44. listen [::]:443 ssl;45. root /app/;46. index index.html;47. server_name laotie666.xyz www.laotie666.xyz;48.}

申请一个自签证书:

49.icestone@icestone-nb:/app$ openssl req -new -x509 -nodes -out server.crt -keyout server.key50....+.........+...+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+..+.+...+..+...+.........+...+..................+....+......+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+.....+...+....+..+...+...................

查看当前目录:

51.icestone@icestone-nb:/app$ ll52.总用量 2053.drwxrwxrwx  3 root     root     4096 1111 02:29 ./54.drwxr-xr-x 25 root     root     4096 1111 00:39 ../55.-rw-------  1 icestone icestone    0 1111 02:27 ca.key56.lrwxrwxrwx  1 icestone icestone   20 1111 02:26 openssl.cnf -> /etc/ssl/openssl.cnf*57.-rw-rw-r--  1 icestone icestone 1363 1111 02:29 server.crt58.-rw-------  1 icestone icestone 1704 1111 02:29 server.key

crt和key文件生成了,将其配置在nginx的配置中:
修改/etc/nginx/sites-available/default:
在与原来server上修改

59. sserver {60. listen       443 ssl;61. index index.html index.htm index.nginx-debian.html;62.63. server_name icestone.art www.icestone.art;64.65. location ~ \.PHP$ {66.   fastcgi_split_path_info ^(.+\.php)(/.+)$;67.   fastcgi_pass unix:/run/php-fpm/www.sock;68.   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;69.   fastcgi_index index.php;70.   include fastcgi_params;71. }72. ssl_certificate      /app/server.crt;73. ssl_certificate_key  /app/server.key;74.}

这里icestone.art使我们即将使用的域名,域名在、etc/hosts下直接添加并刷新即可,
要注意linux下回环地址是0.0.0.0
75. https访问:
在这里插入图片描述

点查看证书:
在这里插入图片描述
强制访问:
在这里插入图片描述
76. 安装php
sudo apt install php libapache2-mod-php

77.icestone@icestone-nb:/app$ sudo apt install php-fpm78.正在读取软件包列表... 完成79.正在分析软件包的依赖关系树... 完成80.正在读取状态信息... 完成                 81.将会同时安装下列软件:82.  php8.1-fpm

注意这里显示安装的是php8.1-fpm,运行检查:
systemctl status php8.1-fpm

83.icestone@icestone-nb:/app$ systemctl status php8.1-fpm84.● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager85.     Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor preset: enabled)

success
配置php运行端口和允许端口:
修改 /etc/php/8.1/pool.d/www.conf
修改下面三个:

86.;下面这个注释掉87.;listen = /run/php/php8.1-fpm.sock88.;修改:89.listen = localhost:8190.listen.allowed_clients = 127.0.0.1

修改nginx中监听php的端口;
修改 /etc/nginx/sites-available/default
主要修改80端口和443端口下启动页面,监听php的端口:

91.server {92. listen 80 default_server;93. listen [::]:80 default_server;94. index index.php index.html index.htm index.nginx-debian.html;95. root /app/www/;96. server_name icestone.art www.icestone.art _;97. location / {98.   try_files $uri $uri/ /index.php$is_args$args;99. }100. location ~ \.php$ {101.   fastcgi_split_path_info ^(.+\.php)(/.+)$;102.   fastcgi_pass localhost:81;103.         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;104.   fastcgi_index index.php;105.   include fastcgi_params;106. }107.}108.109.server {110. listen 443 ssl;111. index index.php index.html index.htm index.nginx-debian.html;112. root /app/www/;113. server_name icestone.art www.icestone.art;114. location / {115.   try_files $uri $uri/ /index.php$is_args$args;116. }117. location ~ \.php$ {118.   fastcgi_split_path_info ^(.+\.php)(/.+)$;119.   fastcgi_pass localhost:81;120.         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;121.   fastcgi_index index.php;122.   include fastcgi_params;123. }124. ssl_certificate      /app/server.crt;125. ssl_certificate_key  /app/server.key;126.}127.

nginx和php重启,访问浏览器端:
在这里插入图片描述

来源地址:https://blog.csdn.net/ice_stone_kai/article/details/127838484

--结束END--

本文标题: ubuntu22.4配置nginx和php

本文链接: https://www.lsjlt.com/news/415092.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • ubuntu22.4配置nginx和php
    实验操作步骤 安装ngix 这里使用命令: sudo apt install nginx 2.icestone@icestone-nb:~$ sudo apt install nginx3.[sudo...
    99+
    2023-09-22
    nginx php
  • nginx+php配置
    安装php yum install php #检查版本 php -v 安装nginx(根据我们自己的Nginx安装,以下可以不看) yum install nginx或者执行下面的步骤: 安装: 1.在vim /etc/p...
    99+
    2023-08-31
    nginx php 运维
  • 怎么配置nginx和php-fpm
    这篇文章主要讲解了“怎么配置nginx和php-fpm”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么配置nginx和php-fpm”吧!在php7中,最不可少的就是nginx和php-f...
    99+
    2023-06-20
  • nginx+php-fpm的安装和配置
    环境         虚拟机:VMware 16.2.4         OS:centos 7.6         远程连接工具:Xshell 7         nginx版本: nginx-1.14.2         php版本:p...
    99+
    2023-09-12
    服务器 nginx php linux
  • Ubuntu如何配置php、nginx和redis
    这篇文章主要介绍“Ubuntu如何配置php、nginx和redis”,在日常操作中,相信很多人在Ubuntu如何配置php、nginx和redis问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Ubuntu如...
    99+
    2023-07-04
  • Linux下怎么配置Nginx和PHP
    本篇内容主要讲解“Linux下怎么配置Nginx和PHP”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux下怎么配置Nginx和PHP”吧!假设我们用PHP实现了一个前端控制器,或者直白点...
    99+
    2023-06-28
  • PHP+Nginx配置备忘
    Nginx支持php脚本解释需要安装php-fpm进程管理器,在php5.3之前版本,php-fpm需要单独安装,之后版本php-fpm集成到PHP解释器之中,编译PHP解释器时需要特别指定配置,不同...
    99+
    2023-09-13
    php nginx 运维
  • 配置 nginx 解析 php
    修改 nginx 配置文件 vim /etc/nginx/nginx.conf 在 server 中插入如下代码: location ~ \.php$ {     try_files $uri =404;     fastcgi_pass ...
    99+
    2023-10-23
    nginx php 运维
  • Day 1-1 PHP-Nginx配置
    Day 1-1 PHP-Nginx配置 配置清单 操作系统:Windows 10数据库:MySQL 8后端编程语言:PHP 7.3(nts即可) PHP框架:Phalcon 3.4 容器:无(无D...
    99+
    2023-10-08
    php nginx 开发语言
  • nginx php-fpm安装配置
    nginx php-fpm安装配置 nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端。 nginx一般是把请求发fas...
    99+
    2023-09-02
    nginx php 运维
  • 聊聊Nginx和Apache配置多版本PHP
    本篇文章给大家带来了关于php的相关知识,其中主要跟大家聊一聊怎么为Nginx和Apache配置多版本PHP,以及如何切割多个conf文件,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。有时候我们的项目不可能都是同一个 PHP 版本,需...
    99+
    2023-05-14
    php nginx apache
  • Nginx和Apache怎么配置多版本PHP
    这篇文章主要讲解了“Nginx和Apache怎么配置多版本PHP”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Nginx和Apache怎么配置多版本PHP”吧!有时候我们的项目不可能都是同一...
    99+
    2023-07-05
  • php+nginx部署wordpress,如何设置nginx配置文件
    文章目录 摘要wordpress文章发布后,nginx报404解决方法处理 413 Request Entity Too Large最终的配置文件 摘要 本文是关于在CentOS上使用Ng...
    99+
    2023-09-02
    php nginx 服务器
  • nginx配置域名和ip
    nginx配置域名和ip 原文链接:https://blog.csdn.net/axe6404/article/details/120918830 1、配置域名和ip同时访问,只需要配置 server_name lanxin.cn,loca...
    99+
    2023-08-19
    nginx tcp/ip 服务器
  • Linux安装配置nginx+php搭建
    Linux安装配置nginx+php搭建 文章目录 Linux安装配置nginx+php搭建1.nginx源码包编译环境和安装相应的依赖1.1 安装编译环境1.2 安装pcre库、zlib库和...
    99+
    2023-09-25
    linux nginx 运维
  • nginx mysql php如何安装配置
    本文操作环境:centos7系统、php 7.2.25版、DELL G3电脑nginx mysql php如何安装配置?CentOS7 下nginx与PHP mysql的安装与配置:下载Nginx  首先安装的依赖包:    gcc aut...
    99+
    2017-05-13
    nginx mysql php
  • nginx mysql php怎么安装配置
    本篇内容介绍了“nginx mysql php怎么安装配置”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!nginx mysql php安装配...
    99+
    2023-06-25
  • Docker配置nginx
    1.Docker安装nginx 安装的命令 sudo docker search nginxdocker pull nginx 查看是否安装 docker images 运行测试nginx docker run --name nginx-...
    99+
    2023-08-20
    docker nginx 运维 ubuntu 服务器
  • 安装配置gunicorn和NGINX的
    博客写得差不多了,打算部署到云上因为速度的关系,不打算部署在AWS上,于是申请了阿里云,环境是上篇文章提到的CentOS 7 64位安装和配置好Python3和MySQL,又稍微了解点web服务器的知识后,打算按这里的方法进行部署,思路是...
    99+
    2023-01-31
    gunicorn NGINX
  • MacOS下安装和配置Nginx
    一、安装brew /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" 按回车后,根据提示操作:输入镜像序号 --> 输...
    99+
    2023-08-24
    nginx macos git
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作