1下载
http://nginx.org/en/download.html
选择稳定版下载。
2 解压后 直接双击nginx.exe
双击后一个黑色的弹窗一闪而过
3 修改配置文件nginx.conf
3.1 修改你的站点名称 我这边还是localhost
3.2
location / {
#root html;
root E:/ts.p2ps.cn;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}
3.3
1 2 3 4 5 6 7 | location ~ \.php$ { root E:/ts.p2ps.cn; 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
在cmd窗口下切换目录 输入命令: nginx.exe
5 修改php.ini配置
修改E:\PHP\php5.5\php5.5.12\ext下的php.ini-development文件,将文件名修改为php.ini,打开php配置文件php.ini:
搜索“extension_dir”,找到: ;extension_dir = “ext” 先去前面的分号再改为 extension_dir = “E:\PHP\php5.5\php5.5.12\ext”
搜索“date.timezone”,找到:;date.timezone = 先去前面的分号再改为 date.timezone = Asia/Shanghai
搜索“enable_dl”,找到:enable_dl = Off 改为 enable_dl = On
搜索“cgi.force_redirect” ;cgi.force_redirect = 1 先去前面的分号再改为 cgi.force_redirect = 0
搜索“fastcgi.impersonate”,找到: ;fastcgi.impersonate = 1 去掉前面的分号
搜索“cgi.rfc2616_headers”,找到:;cgi.rfc2616_headers = 0 先去前面的分号再改为 cgi.rfc2616_headers = 1
搜索“php_mysql”,找到:”extension=php_mysql.dll和extension=php_mysqli.dll 去掉前面的“;”extension=php_mysql.dll和extension=php_mysqli.dll (支持MYSQL数据库)
6 运行php
F:\xmapp\php>php-cgi.exe -b 127.0.0.1:9000 -c php.ini
7 打开浏览器 输入localhost 运行成功
8 停止nginx服务器
nginx -s stop
如果使用cmd命令窗口启动nginx,关闭cmd窗口是不能结束nginx进程的,可使用两种方法关闭nginx
(1)输入nginx命令 nginx -s stop(快速停止nginx) 或 nginx -s quit(完整有序的停止nginx)
(2)使用taskkill taskkill /f /t /im nginx.exe
10 制作批处理命令快速启动与关闭
下载软件RunHiddenConsole.exe:
http://redmine.lighttpd.net/attachments/660/RunHiddenConsole.zip
start_nginx.bat
1 2 3 4 5 6 7 8 9 | @echo off REM set PHP_FCGI_CHILDREN=5 set PHP_FCGI_MAX_REQUESTS=1000 echo Starting PHP FastCGI... F:\nginx-1.14.2\RunHiddenConsole "F:\xmapp\php\php-cgi.exe" -b 127.0.0.1:9000 -c "F:\xmapp\php\php.ini" echo Starting nginx... F:\nginx-1.14.2\RunHiddenConsole "F:/nginx-1.14.2/nginx.exe" -p "F:/nginx-1.14.2/" |
stop_nginx.bat
@echo off echo Stopping nginx... taskkill /F /IM nginx.exe > nul echo Stopping PHP FastCGI... taskkill /F /IM php-cgi.exe > nul exit
就可以双击运行控制启动与停止了。
11 参考资料
https://blog.csdn.net/weixin_41782253/article/details/82706617
12 直接用phpstudy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | #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; server { listen 80; server_name localhost; root E: /ts .p2ps.cn; #access_log /tmp/testing.p2ps.cn.log; #error_log /tmp/testing.p2ps.cn.log; #"upstream sent too big header" issue #nginx 错误 # FirePHP 等造成头部过大的错误 fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; # 设置expires和max-age的时间 location ~* "^.+\.(jpe?g|gif|css|png|js|ico|pdf|zip|tar|t?gz|mp3|wav|swf)$" { expires 30d; log_not_found off; } #location / { # try_files $uri $uri/ /index.php?$args; #} #将request指向index.php location / { index index.php index.html index.htm; if (-f $request_filename) { break ; } if (-d $request_filename) { break ; } rewrite ^(.+)$ /index .php last; } #主程序目录不能被访问 #location /www/{ # deny all; #} location /src/ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root /src/index .php; include fastcgi_params; #client_max_body_size 50m; } #引用PHP CGI location ~ .*\.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_read_timeout 600; include fastcgi_params; } } # 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 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; # } #} } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!