-
搭建Nginx环境,官网下载:nginx.org/en/download… ,解压至指定目录下,在Windows服务器指定目录下新建代理两个项目的文件夹:E:\zhdt\hldjc;E:\zhdt\qwgl。
-
编辑nginx.conf配置文件。
server {
listen 3000; //服务端口
server_name 192.168.90.40;
#charset koi8-r;
#注释
#root与alias主要区别在于nginx如何解释location后面的uri,这会使两者分别以不同的方式将请求映射到服务器文件上。
#root的处理结果是:root路径+location路径
#alias的处理结果是:使用alias路径替换location路径
#alias是一个目录别名的定义,root则是最上层目录的定义。
#还有一个重要的区别是alias后面必须要用“/”结束,否则会找不到文件的。。。而root则可有可无
#access_log logs/host.access.log main;
#方式一:(不配置proxy_pass是因为前端指定了服务端请求地址)
#location / {
# root E:\zhdt\qwgl;
# index index.html index.htm;
#}
#location /zhdt/hldjc/ {
# root E:;
# index index.html index.htm;
#}
#location /zhdt/qwgl/ {
# root E:;
# index index.html index.htm;
#}
#方式二:
location / {
alias E:/zhdt/qwgl/;
index index.html index.htm;
}
location /zhdt/hldjc {
alias E:/zhdt/hldjc/;
index index.html index.htm;
}
location /zhdt/qwgl {
alias E:/zhdt/qwgl/;
index index.html index.htm;
}
#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_param SCRIPT_FILENAME /scripts$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;
#}
}
- 保存配置文件,打开cmd进入指定目录盘下:cd E:\Nginx\nginx-1.20.1\conf,输入命令行重启Nginx(nginx -s reload)
- 在浏览器访问Nginx代理的服务:http://192.168.90.40:3000