Nginx+Php服务器环境部署
1、安装环境及软件版本
1.1 windows版本 10
1.2 php服务版本:php-5.2.17-nts-Win32-VC6-x86
1.3 nginx版本:nginx-1.20.1
2、php.int配置修改
extension_dir = "C:\demo\soft\nginx-php-7.4.22-nts-Win32-vc15-x64\ext"
cgi.fix_pathinfo=1
;extension=php_bz2.dll
extension=php_curl.dll
extension=php_dba.dll
extension=php_dbase.dll
;extension=php_fdf.dll
extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
;extension=php_exif.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_msql.dll
;extension=php_mssql.dll
extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
extension=php_snmp.dll
extension=php_soap.dll
extension=php_sockets.dll
extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
extension=php_xsl.dll
extension=php_zip.dll
3、nginx.conf配置
server {
listen 80;
listen 127.0.0.1:80;
server_name localhost;
root html/web;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
index index.php index.html index.htm;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php$1 last;
}
}
#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;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ [^/]\.php(/|$) {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#重点,关键配置,这里踩坑的几率很大。解决路径访问不到的问题。
include fastcgi.conf;
#fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# 第一种配置,简单php配置
#下面这里要改看清楚原本是/script$fastcgi_script_name,改成$document_root$fastcgi_script_name; #$document_root其实就是上面的root,可以直接改成绝对路径E:/self/www$fastcgi_script_name
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param PATH_INFO $fastcgi_path_info;
#fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
#include fastcgi_params;
# 第二种配置,ThinkPHP配置
#定义变量$fastcgi_script_name_new赋值为$fastcgi_script_name变量
set $path_info "";
set $fastcgi_script_name_new $fastcgi_script_name;
#判断url是否是pathinfo形式的,如果是则把这个url分割成两部分,index.php入口文件之后的pathinfo部分存入$path_info变量中,
#剩下的部分和$document_root根目录定位index.php入口文件在文件系统中的绝对路径 .
if ($fastcgi_script_name ~* "^(.+\.php)(/.+)$" ) {
set $fastcgi_script_name_new $1;
set $path_info $2;
}
#对fastcgi.conf中的SCRIPT_FILENAME和SCRIPT_NAME fastcgi参数进行重写,目的是指定入口文件在文件系统中的绝对路径给script_filename参数,让fastcgi知道index.php文件位置。
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name_new;
fastcgi_param SCRIPT_NAME $fastcgi_script_name_new;
#定义一个新的nginx服务器传递给fastcgi的参数PATH_INFO,thinkphp需要这个入口文件index.php后的pathinfo信息
fastcgi_param PATH_INFO $path_info;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.ht {
deny all;
}
}
4、启动文件
4.1 启动 start.bat
@echo off
set PHP_FCGI_MAX_REQUESTS = 1000
REM 设置Nginx和php-cgi的目录
SET php_home=D:/tools/nginx-php-5.2.17-nts-Win32-VC6-x86/
SET nginx_home=D:/tools/nginx-1.20.1-hake-php/
REM 解决php偶尔退出的情况
set xxfpm_home=D:/tools/startweb/xxfpm/bin/
rem 设置后台jar文件包目录
SET back_home=D:/tools/back/
echo Starting PHP FastCGI...
rem 下面这里的分别替换成你的php-cgi.exe和php.ini的路径
rem RunHiddenConsole %php_home%php-cgi.exe -b 127.0.0.1:9000 -c %php_home%php.ini
RunHiddenConsole %xxfpm_home%xxfpm.exe "%php_home%php-cgi.exe -c %php_home%php.ini" -n 5 -i 127.0.0.1 -p 9000
echo Starting nginx...
rem 注意替换成你的nginx目录
RunHiddenConsole %nginx_home%nginx.exe -p %nginx_home%
echo Starting zhfsback...
start javaw -jar %back_home%hakesmart-0.0.1-SNAPSHOT.jar
echo Starting fsaqback...
start javaw -jar %back_home%hake-0.0.1-SNAPSHOT.jar
4.2 停止服务stop.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 xxfpm...
taskkill /F /IM xxfpm.exe > nul
exit
亲测通过。
每天进步一点点!