当前位置: 首页 > news >正文

ubuntu nginx 配置php 网站

1.安装nginx

sudo apt-get install nginx

2.安装php 和php-fpm

sudo apt-get install phpsudo apt-get install php-fpm

3.配置ngixn

进入/etc/nginxg/sites-enabled

vim default //notice 这里只能有一个default的文件 放两个nginx会把报错

完整配置如下

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
### Default server configuration
#
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.php 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/php8.1-fpm.sock; //修改点这里根据电脑安装的php版本来#	# With php-cgi (or other tcp sockets):#	fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; //修改点include fastcgi_params; //修改点}# 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;
#	}
#}

4.创建一个php文件写个最简单的 index.php

<?php
phpinfo();

5.将这个index.php拷贝到nginxi的webroot  即/var/www/html  在nginx 的nginx。conf文件下有配置这个路径

6.启动php fpm解释 

sudo systemctl start php8.1-fpm.service //这个后缀根据你安装的版本来

7.打开浏览器输入127.0.0.1/index.php就可以可以看到页面啦 !

相关文章:

  • (3)医疗图像处理:MRI磁共振成像-快速采集--(杨正汉)
  • pip(包管理器) for Python
  • 基于深度学习OCR文本识别
  • 1791.找出星形图的中心节点
  • zdppy_mcrud操作MySQL数据库教程
  • Leetcode 第 130 场双周赛题解
  • 【Hive SQL 每日一题】行列转换
  • Centos 停服倒计时!你的操作系统何去何从?
  • C++小病毒
  • 正则项学习笔记
  • Windows:iHasher-v0.2安装报错Windows 功能 .NET Framework 3.5
  • 2024年 电工杯 (A题)大学生数学建模挑战赛 | 园区微电网风光储协调优化配置 | 数学建模完整代码解析
  • 【ChatGPT】 Microsoft Edge 浏览器扩展使用 GPT
  • 【会议征稿,IEEE独立出版】第四届计算机技术与信息科学国际研讨会(ISCTIS 2024)
  • Java面试八股之有哪些线程安全的集合类
  • 5分钟即可掌握的前端高效利器:JavaScript 策略模式
  • Android开发 - 掌握ConstraintLayout(四)创建基本约束
  • CSS居中完全指南——构建CSS居中决策树
  • gops —— Go 程序诊断分析工具
  • JavaScript实现分页效果
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • Spring Boot MyBatis配置多种数据库
  • 从 Android Sample ApiDemos 中学习 android.animation API 的用法
  • 分布式熔断降级平台aegis
  • 基于Dubbo+ZooKeeper的分布式服务的实现
  • 前端攻城师
  • 一份游戏开发学习路线
  • 《天龙八部3D》Unity技术方案揭秘
  • puppet连载22:define用法
  • ​ 轻量应用服务器:亚马逊云科技打造全球领先的云计算解决方案
  • #define MODIFY_REG(REG, CLEARMASK, SETMASK)
  • #pragma once与条件编译
  • %3cli%3e连接html页面,html+canvas实现屏幕截取
  • (14)目标检测_SSD训练代码基于pytorch搭建代码
  • (void) (_x == _y)的作用
  • (WSI分类)WSI分类文献小综述 2024
  • (二)JAVA使用POI操作excel
  • (附源码)spring boot球鞋文化交流论坛 毕业设计 141436
  • (附源码)springboot太原学院贫困生申请管理系统 毕业设计 101517
  • (附源码)ssm高校升本考试管理系统 毕业设计 201631
  • (附源码)ssm考试题库管理系统 毕业设计 069043
  • (亲测)设​置​m​y​e​c​l​i​p​s​e​打​开​默​认​工​作​空​间...
  • (推荐)叮当——中文语音对话机器人
  • (转)我也是一只IT小小鸟
  • (自用)交互协议设计——protobuf序列化
  • .mkp勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复
  • .NET IoC 容器(三)Autofac
  • .NET 直连SAP HANA数据库
  • .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序)...
  • .NET_WebForm_layui控件使用及与webform联合使用
  • .net连接MySQL的方法
  • .Net面试题4
  • .Net实现SCrypt Hash加密
  • .pings勒索病毒的威胁:如何应对.pings勒索病毒的突袭?
  • /ThinkPHP/Library/Think/Storage/Driver/File.class.php  LINE: 48