nginx+php配置
一、下载文档
1.下载php: https://windows.php.net/download/https://windows.php.net/download/ (注意,需下载正确的文件,最好下载Thread Safe安全版,我就是因为下载错文件,绕了好久。)
2.下载nginx: nginx: downloadhttp://nginx.org/en/download.html
二、配置nginx
修改Nginx的conf文件,Nginx的配置文件默认位置为:/etc/nginx/nginx.conf
1. 去掉worker_processes前的#号,开启一个进程
2. 添加events
3. 设置http->设置server->支持php
...
worker_processes 1;
...
events {worker_connections 1024;
}
....
server {listen 801;server_name localhost;...location / {root html;index index.html index.htm index.php;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}}
4.测试nginx是否安装成功
启动命令:start nginx
在浏览器输入:http://localhost:801/,就会打开html下的index.html文件
如果不能正常打开,查看端口号是否被占用
三、配置php
复制php.ini-development,命名为“php.ini",开始进行配置
1.查找doc_root,配置需访问的源码目录
doc_root ="D:/.../nginx-1.16.1/html"
2.查找extension_dir,配置目录
extension_dir = "D:/.../php-8.0.12/ext"
3.查找cgi.fix_pathinfo,设置为0
搜索“php_mysql”,找到:”extension=php_mysql.dll和extension=php_mysqli.dll 去掉前面的“;”extension=php_mysql.dll和extension=php_mysqli.dll (支持MYSQL数据库)
四、配置完成后,在cmd输入“php-cgi.exe -b 127.0.0.1:9000” 命令,确保“127.0.0.1:9000“的地址与nginx.conf中的 location ~ \.php$ 中的地址一样。如果cmd窗口关闭的话,服务关闭,就不能正常访问php页面,如果不需要cmd窗口,让服务在后台运行,可进行第五步骤
五:后台启动服务
1.在php目录下新建文件php-cgi.vbs,用php-cgi.vbs文件启动php-cgi:打开php-cgi.vbs,写入启动编码:
set wscriptObj = CreateObject("Wscript.Shell")
wscriptObj.run "php-cgi -b 127.0.0.1:9000",0
2.在Nginx目录下新建启动项:runServer.bat和停止项stopServer.bat
在启动项runServer.bat中输入:
@echo off
echo Starting nginx...
cd %~dp0nginx
start "" "D:/.../nginx-1.16.1/nginx.exe"#echo Starting mysql...
#net start mysqlecho Starting PHP FastCGI...
cd %~dp0PHP
start "" "D:/.../php-8.0.12/php-cgi.vbs"pauseExit
在停止项stopServer.bat中输入:
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
echo Stopping mysql...
net stop mysql
pause
exit
附上nginx.conf配置
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;
}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;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;gzip on;gzip_min_length 1k;gzip_comp_level 9;gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;gzip_vary on;gzip_disable "MSIE [1-6]\.";server {listen 801;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm index.php;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;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;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root D:\software\nginx-1.16.1\html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}
nginx+php配置相关推荐
- nginx技术(2)nginx的配置详解
nginx的配置 1,启动nginx 1 2 3 4 5 6 7 [root@centos6 nginx-1.2.9]# /usr/sbin/nginx -c /etc/nginx/nginx.con ...
- 实现nginx上配置免费证书Let's Encrypt
Let's Encrypt 的免费证书有效期为三个月,不过可以免费续期,写一个脚本定期更新即可. 准备一台nginx 服务器 ,将以下三个附件上传到你的nginx服务器. 1.下载脚本文件,wget ...
- 推荐一款 Nginx 可视化配置神器
以下文章来源方志朋的博客,回复"666"获面试宝典 来源:逛逛GitHub Nginx 是前后端开发工程师必须掌握的神器.该神器有很多使用场景,比如反向代理.负载均衡.动静分离.跨 ...
- 九爷带你了解 nginx 日志配置指令详解
nginx日志配置指令详解 日志对于统计排错来说非常有利的. 本文总结了nginx日志相关的配置如 access_log.log_format.open_log_file_cache.log_not_ ...
- php和nginx安装脚本,Nginx + PHP 配置和启动脚本
Nginx + PHP 配置和启动脚本,很实用 # nginx.conf server { listen 8080 ; server_name localhost; location / { root ...
- php修改后nginx返回不生效,nginx修改配置后不生效的问题
nginx增加了新的server name配置,发现nginx -s reload之后总是不生效. http和https均可以打开页面,但是页面是别的server页面,使用的证书也是别的server的 ...
- nginx lua 配置cc 防攻击-使用lua 配置黑白名单
nginx lua 配置cc 防攻击-使用lua 配置黑白名单 cc 防攻击和ip 禁止期限 lua_shared_dict _dict 1m; lua_shared_dict _blacklist ...
- nginx基本配置与参数说明
user nobody; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 #error_log logs/error.log; #er ...
- 用Nginx如何配置运行无扩展名PHP文件或非.PHP扩展名文件
用Nginx如何配置运行无扩展名PHP文件或非.PHP扩展名文件 使用Apache + PHP 很容易做到运行无扩展名的PHP文件. 在Nginx中能做到吗?是可以的. 只需将nginx.conf文件 ...
- Nginx安全配置研究
Nginx安全配置研究 zhangsan · 2014/03/28 10:39 0x00 测试环境 操作系统:CentOS6.5 Web服务器:Nginx1.4.6 Php版本:Php5.4.26 0 ...
最新文章
- 《第一行代码》学习笔记18-广播接收器Broadcast_Receiver(1)
- go预防CSRF攻击
- Shell until循环
- [已解决] java 增加 ALPN支持
- 爆赞!Jetpack-MVVM-高频提问和解答,满满干货指导
- linux资源使用统计指南,指南:工作量分析文档
- 创建代码生成器可以很简单:如何通过T4模板生成代码?[上篇]
- CSS实现垂直居中布局
- mysql 跨服务器 etl_mysql数据库跨服务器查询【需要确定mysql支持FEDERATED ,可以参照文章内容自己配置】...
- 51 -算法 -LeetCode 53最大子序和 动态规划
- (第九章)多表查询之all,any
- python数据分析之(1)数据输入和输出
- python脚本调度程序_python任务调度实例分析
- 论文笔记(五)面向大规模智能计量的分布式差分隐私
- Eel——js 如何调用python的函数
- Android 6.0 更新包与已安装应用的签名不一致
- 文件共享总结上篇-Windows之间文件共享
- 如何判断鼠标按下的是左键还是右键
- 1亿条数据批量插入 MySQL,哪种方式最快?
- 组合数学(四)生成排列和组合
热门文章
- Linux进程、线程、任务调度(1)贵在坚持
- codewars python Regex validate PIN code
- 2741. [济南集训 2017] 掰巧克力
- 使用Ant构建简单项目
- 走迷宫(二):在XX限制条件下,是否走得出
- 使用 :after伪元素撑开 div
- (转)JS页面间传值
- TCP拥塞控制算法内核实现剖析(一)
- Linux系统中僵尸进程的查看与删除
- spring中如何实现参数隐式传递_Java进阶架构之开源框架面试题系列:Spring+SpringMVC+MyBatis(含答案分享)...