NGINX配置PHP网站

article/2025/3/16 23:52:52

NGINX配置PHP网站

  • NGINX配置PHP网站
    • 源码安装NGINX
    • 安装PHP
    • 修改PHP参数
    • 重启PHP
    • 修改nginx配置文件
    • 重启NGINX
    • 测试
    • 解决报错问题

NGINX配置PHP网站

源码安装NGINX

脚本一键安装:
安装路径:/opt/nginx
源码路径:/root/

 #!/bin/bash
useradd -s /sbin/nologin nginx               #创建一个不能登陆系统的用户nginx#Installation dependence
yum groupinstall -y "Development tools"
yum install -y gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel
yum install -y pcre-devel pcre zlib zlib-devel openssl openssl-devel wget gcc gcc-c++ unzip
yum -y install git#Download source
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -xvf nginx-1.20.1.tar.gz -C /opt#Compile and install
cd /opt/nginx-1.20.1/
sed -i '49s/nginx/Microsoft-IIS/' src/http/ngx_http_header_filter_module.c
sed -i '50s/: /: Microsoft-IIS/' src/http/ngx_http_header_filter_module.c
sed -i '51s/: /: Microsoft-IIS/' src/http/ngx_http_header_filter_module.c
./configure \
--prefix=/opt/nginx/ \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module 
make && make install
ln -s /opt/nginx/sbin/nginx  /usr/bin/nginx
nginx
ps -aux|grep nginx


安装PHP

wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm  
yum install -y ./remi-release-7.rpm 
yum install -y php72-php-devel php72-php-fpm php72-php-mbstring php72-php-memcache php72-php-redis php72-php-mysqli php72-php-mysqlnd php72-php-pdo php72-php-bcmath php72-php-dom php72-php-gd php72-php-gmp php72-php-igbinary php72-php-imagick php72-php-mcrypt php72-php-pdo_mysql php72-php-posix php72-php-simplexml php72-php-opcache php72-php-xsl php72-php-xmlwriter php72-php-xmlreader php72-php-xml php72-php-swoole php72-php-zip php72-php-fileinfo curl curl-devel net-snmp net-snmp-devel perl-DBI ntpdate libxml2-devel libevent-devel yum-utils pcre pcre-devel openssl  openssl-devel zlib zlib-devel gcc gcc-c++


修改PHP参数

路径:/etc/opt/remi/php72/php-fpm.d/www.conf

vim /etc/opt/remi/php72/php-fpm.d/www.conf
修改参数:
max_execution_time=300 #修改为300
post_max_size=16M
upload_max_filesize=8M
max_input_time=300

date.timezone=“Asia/Shanghai” #增加
always_populate_raw_post_data=-1 #增加



重启PHP

systemctl restart php72-php-fpm



修改nginx配置文件

方法一:在默认的nginx.conf修改
方法二:添加conf.d 目录增加配置文件添加PHP配置

推荐方法2
方法一:
cp -r /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf.bak
vim /opt/nginx/conf/nginx.conf +65

往下拉到 location ~ .php$位置
在这里插入图片描述

  1. 按 L或者右方向键到#号
  2. Crtl+v 可视化选项
  3. 按 j 键往下拉或按方向箭头往下键选中要取消注释的配置
  4. 再按 s 键就会把# 号去掉了
  5. 修改配置
    把 fastcgi_params 更改为fastcgi.conf ;注释掉这行 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    在这里插入图片描述

方法2:
默认文件配置文件不用修改 /opt/nginx/conf/nginx.conf
或者重新写入默认配置文件。这个是经常使用的nginx配置文件可以粘贴覆盖默认文件 /opt/nginx/conf/nginx.conf

worker_processes  auto;
error_log		logs/error.log error;
pid		logs/nginx.pid;
events {	worker_connections  65535;multi_accept on;
}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"';access_log	 logs/access.log main;keepalive_timeout  60;add_header Access-Control-Allow-Origin '*';add_header Access-Control-Max-Age '3628800';add_header Access-Control-Allow-Credentials 'true';add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';add_header Access-Control-Allow-Methods 'GET,POST,PUT,OPTIONS';underscores_in_headers on;	client_header_buffer_size	32k;client_body_buffer_size	20m;client_max_body_size	120M;client_header_timeout	1m;client_body_timeout		1m;proxy_connect_timeout    600;proxy_read_timeout       600;proxy_send_timeout       600;large_client_header_buffers	4	32k;fastcgi_buffers		4	128k;fastcgi_buffer_size		128k;fastcgi_busy_buffers_size	256k;server_tokens off;tcp_nopush on;tcp_nodelay on;sendfile        on;gzip  on; #开启gzip#gzip_static on;gzip_vary on;gzip_min_length 1k;gzip_buffers 8 32k;gzip_http_version 1.1;gzip_comp_level 6; gzip_proxied any;gzip_types application/javascript application/json text/css image/png;real_ip_header		X-Real-IP;proxy_set_header        Host            $host:$server_port;proxy_set_header        X-Real-IP       $remote_addr;proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;   include      /opt/nginx/conf.d/*.conf;
}

添加子目录
mkdir /opt/nginx/conf.d
touch /opt/nginx/conf.d/test_php.conf

添加php项目
vim /opt/nginx/conf.d/test_php.conf

server {listen      80 ;server_name  localhost;location / {root   /home/test;index  index.php index.htm index.html;}location ~ \.php$ {root          /home/test;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;#fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;include        fastcgi.conf;}}


重启NGINX

nginx -t
nginx -s reload


测试

vim /home/test/test.php

<?php$i="This is a test Page";echo $i;
?>


解决报错问题

部署项目后:
如果出现 No input file specified.
看项目下面是不是多了 .user.ini文件
ls -la 查看项目下面




http://chatgpt.dhexx.cn/article/eC9qUlOk.shtml

相关文章

【Nginx和PHP教程(一)】安装、配置及初步使用

1. nginx基本介绍 2. nginx安装和环境配置 3. php基本介绍 4. php的安装和环境配置 5. JavaScript、php、html等的区别 6. ubuntu系统中php的安装和环境配置 1. nginx基本介绍 Nginx&#xff08;发音为“engine X”&#xff09;是一款高性能的、轻量级的Web服务器软件&am…

JADE开发求助

求助&#xff1a;JADE创建Agent时遇到这种情况是怎么回事&#xff1f;

Jade入门学习

title: Jade入门学习 date: 2018-05-17 20:09:31 tags: [jade, pug] jade是超高性能的node JavaScript模板引擎&#xff0c;有着非常强大的API和大量杰出的特性。它主要针对node的服务端。由于商标的原因&#xff0c;改为Pug&#xff0c;哈巴狗。Pug有它本身的缺点——可移植性…

Jade linux 位置,jade 6.5 安装教程

简介&#xff1a; MDI Jade是一款XRD分析软件&#xff0c;可以分析X射线衍射&#xff0c;分析出衍射图谱&#xff0c;获得材料的成分、材料内部原子或分子的结构或形态等信息的研究手段。 MDI Jade可以对X射线衍射进行分析&#xff0c;通过分析得到的结果&#xff0c;软件可以判…

jade支持html,Jade !HTML框架

1.电脑要有nodejs npm install jade -g 3.pwd 4.subl .打开编译器 格式为jade的文件 5.jade jadetut.jade 编译 安装 $ npm install jade --global -usage $ jade [options] [dir|file ...] Options: -h, --help output usage information pads pagers set-top boxes 语法 incl…

MDI Jade6.5安装教程-附安装包

安装软件前&#xff0c;请退出360、腾讯电脑管家等安全和杀毒软件。 1&#xff0e;双击setup.exe 2&#xff0e;选择是 3.下一步 4.同意许可协议&#xff0c;下一步 5.下一步&#xff08;默认不要改&#xff09;&#xff0c;如果需要更改&#xff0c;希望只更改盘符&am…

java模板引擎 jade_jade模板引擎

jade是使用JavaScript实现&#xff0c;可供nodejs使用的高性能模板引擎(性能高不高&#xff0c;有些争议。姑且称之为高性能吧&#xff01;)。模板引擎有很多&#xff0c;主要使用比较广泛的是jade和ejs&#xff0c;modejs项目默认使用jade作为模板引擎&#xff0c;我也就不多说…

jade java_JADE提升篇

以下如果未特殊声明&#xff0c;都在JADE管理器中运行&#xff0c;然后再Eclipse控制台中查看&#xff01; JADE行为类 在前面的例子中&#xff0c;Agent所作的工作都定义在了setup方法中&#xff0c;实际上它具有的行为和执行的动作都应该定义在Behavious类中&#xff0c;我们…

Windows系统缺失jade6.dll文件导致程序无法运行解决办法

其实很多用户玩单机游戏或者安装软件的时候就出现过这种问题&#xff0c;如果是新手第一时间会认为是软件或游戏出错了&#xff0c;其实并不是这样&#xff0c;其主要原因就是你电脑系统的该dll文件丢失了或没有安装一些系统软件平台所需要的动态链接库&#xff0c;这时你可以下…

JADE平台搭建

首先从下列官方网站下载必要的软件或文件。 JADE官方网站&#xff1a;http://jade.tilab.com/&#xff1b; JAVA环境搭建之JDK官网&#xff1a;http://www.oracle.com/technetwork/java/javase/downloads/index.html eclipse软件下载&#xff1a;https://www.eclipse.org/do…

html jade文件,Jade模板

Express框架里内嵌了Jade模板引擎。正好项目里也要用到&#xff0c;本篇整理了下Jade的相关用法。 安装与执行 标签和属性 多行文本 变量 语句 Mixin 模板 注释 过滤器 安装与执行 安装很简单&#xff1a; npm install jade –global 安装后本地随便新建一个sample.jade文件&am…

MDI Jade6的安装(含ocx控件的安装、PDF索引建立、修改注册表)

前言 关于介绍及安装jade的资料及教程&#xff0c;上小木虫、六维、百度等一搜一大堆&#xff0c;这里不再详细介绍及逐一列举。 这里只谈干货&#xff0c;里面很多问题需要仔细摸索解决&#xff0c;这里就一一说明了。 记住&#xff1a;不管是安装文件还是所需要的文件&…

Jade6安装及PDF卡片导入

2020年是中国脱贫攻坚的收官之年&#xff0c;也是全面建成小康社会的关键一年。在这样一个具有标志性意义的年代&#xff0c;我觉得应该没有人像我一样还用着过渡版的Windows 8了。别问为什么不装Windows 10&#xff0c;因为电脑带不动&#xff0c;毕竟伴随我进行了十年的艰苦征…

Ubuntu系统重装Ubuntu系统

系统环境&#xff1a;Ubuntu18.04 目的&#xff1a;重装Ubuntu系统 步骤&#xff1a; 1. sudo usb-creator-gtk 2. 选择iso系统文件 Ubuntu 18.04.4.XXX.iso 3. 选择u盘&#xff0c;并选择Make Startup Disk 4. 制作完成后重启电脑&#xff0c;长按F12(联想笔记本&#xf…

【2021】重装ubuntu16.04系统

2021年3月3日19点47分 本人因为种种原因导致ubuntu16.04系统崩溃&#xff0c;现需要重装系统&#xff0c;故记录下这次重装ubuntu之旅。 原因&#xff1a;ubuntu16.04 - 检测到系统程序出现问题 一直在登录用户的界面&#xff0c;登录进去后再闪退出来&#xff0c;一直循环登…

重装Ubuntu系统及系列软件安装

重装Ubuntu系统及系列软件安装 【1】安装ubuntu20.04.03系统下载Ubuntu20.04.03系统更换系统apt的源 【2】CUDA和cudnn安装下载CUDA安装包并安装 【3】pycharm的安装【4】conda的安装【5】兼容Tf1和30显卡 【1】安装ubuntu20.04.03系统 下载Ubuntu20.04.03系统 【下载地址】h…

双系统重装Ubuntu

完全删除Ubuntu 1、右键此电脑-管理-磁盘管理&#xff0c;删除Ubuntu所在卷&#xff08;Ubuntu EFI分区无法删除&#xff09; 2、删除Ubuntu EFI分区 ①Win R 输入cmd打开终端&#xff0c;输入 diskpart 进入磁盘工具 ②输入 list disk 查看磁盘&#xff0c;输入 select d…

Windows重装Ubuntu系统

一&#xff0c;去官网下载Ubuntu镜像 二、下载镜像安装工具&#xff08;win32diskManger&#xff09; 下载之后完成安装 三、制作Ubuntu安装盘 打开win32diskManger 选择镜像文件&#xff0c;选择u盘&#xff0c;确认后写入&#xff0c;请备份好资料&#xff0c;写入后数据会格…

Ubuntu16.04重装系统

Ubuntu16.04重装系统 安装显卡驱动第一步 禁用nouveau第二步 下载驱动第三步 进入命令行模式&#xff0c;关闭lightdm第四步 安装显卡驱动第五步 查看Nivida 设置更新与源地址步骤 安装gnome桌面安装搜狗输入法安装谷歌浏览器安装Anaconda3安装Pycharm安装keras下载Cuda安装cuD…

装机(一) ubuntu server 系统安装图文教程

装机任务为Dell C4130服务器&#xff0c;安装ubuntu16.04系统&#xff0c;无图形界面。 第一步为了安装ubuntu系统我们需要先下载合适的系统&#xff0c;这里我们下载了ubuntu16.04LTS服务器版本&#xff0c;也就是server版本的系统。可以去官方网站下载http://www.ubuntu.org…