window使用phpStudy在nginx部署前端测试

想在window快速部署前端项目使用nginx代理测试

安装下载phpStudy

点击启动nginx

打开nginx的文件位置

在conf文件夹下打开nginx.conf配置

配置好配置文件,例如前端的dist文件路径,后端代理路径等

powershell 复制代码
#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       8082;
        server_name  192.168.2.100;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html\dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html; #解决页面刷新404问题
        }

        location /admin-api {
            proxy_pass http://192.168.2.100:48080;
        }        
       
		
		location /infra/ws {
            proxy_pass http://192.168.2.100:48080/infra/ws;
			proxy_buffering off;  # 禁用缓冲
			chunked_transfer_encoding off;  # 禁用分块传输编码
			proxy_cache off;  # 禁用缓存
			proxy_set_header Connection '';  # 保持连接
			proxy_http_version 1.1;  # 使用HTTP 1.1
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
			proxy_set_header Host $host;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Forwarded-Proto $scheme;
        }        

        #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;
        #}
    }


    # 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;
    #    }
    #}

}

最后,重启nginx,就可以正常访问了

相关推荐
运维螺丝钉3 小时前
docker安装应用
运维·docker·容器
WordPress学习笔记3 小时前
解决Bootstrap下拉菜单一级链接无法点击的问题
前端·bootstrap·html
Never_Satisfied3 小时前
C#插值字符串中大括号表示方法
前端·c#
以太浮标3 小时前
华为eNSP模拟器综合实验之- 路由表RIB和转发表FIB的关联解析
运维·网络·华为·信息与通信
optimistic_chen3 小时前
【Docker入门】cgroups 资源控制
linux·运维·ubuntu·docker·容器·cgroup
LXY_BUAA3 小时前
《嵌入式操作系统》_内核编译练习与配置文件讲解_20260119
linux·运维·服务器
踢球的打工仔4 小时前
typescript-类
前端·javascript·typescript
天天打码4 小时前
Svelte-无虚拟DOM、极致性能的现代高性能Web开发框架!
前端·node.js·vue·svelte
0思必得04 小时前
[Web自动化] Selenium元素定位
前端·python·selenium·自动化·html
触想工业平板电脑一体机4 小时前
【触想智能】MES工位一体机在自动化生产线上的作用和市场应用前景分析
大数据·运维·自动化