Win10系统--WEB服务器配置
Win10系统--WEB服务器配置
配置要求
-
在Windows环境下安装并配置Nginx服务器
-
在M:盘下新建一个文件夹Web作为网站根目录,并修改Nginx中对应设置
-
在新的Web根目录中编写一个测试用的HTML文档并测试是否能正常访问
-
完成Nginx中PHP语言支持模块的安装及配置
-
写一个.php页面,通过phpinfo()函数测试服务器是否正常支持PHP语言模块
(1)配置nginx环境如下
修改M:\nginx-1.15.3\conf\nginx.conf配置文件如下:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
出现如下错误提示:
现修改端口参数:
server {
listen 8088;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
服务器正常启动:
在360极速浏览器中测试:
(2)(3)M盘中新建访问文件夹,并修改默认文档和相关配置路径
server {
listen 8088;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root M:\web;
index index.html index.htm;
}
在360极速浏览器中测试:
正常访问!
(4)修改PHP配置文件如下:
启动PHP的cgi模块:
修改conf\nginx.conf配置文件如下:
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;
}
重启nginx服务器:
(5)编写PHP测试文档:
访问M:\web\first.php如下:
调试代码如下:
server {
listen 8088;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
if (!-e $request_filename) {
rewrite ^/comic-detail-(\d+)/ /mh-$1/ permanent;
rewrite ^/comic-detail-(\d+)/(\d+)/ /mh-$1/$2/ permanent;
rewrite ^/show-(\d+)-(\d+)/ /mh-$1/$2/ permanent;
rewrite ^/show-(\d+)-(\d+)-(\d+)/ /mh-$1/$2-$3/ permanent;
rewrite ^/mh-(\d+)/(\d+)/$ /read-comic-$1-$2/ last;
rewrite ^/mh-(\d+)/(\d+)-(\d+)/$ /read-comic-$1-$2-$3/ last;
rewrite "^/uploads/manhua/\d+/\d{4}-(\d{3})-(\d{2})-(\d{2})-(\d{2})-(\d+)-(.*)$" /static/comic2/$1/$2/$3/$4/$5/$6 last;
rewrite ^/(.*)$ /index.php?$1 last;
}
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
#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:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
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;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
(6)自定义页面调试:
正常启动!
自定义代码:
12.php
<?php
phpinfo();
?>