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,就可以正常访问了

相关推荐
Crazy________2 小时前
38nginx四层负载均衡配置,和动静分离解析
linux·运维·nginx·负载均衡
Winslei2 小时前
【hvigor专栏】OpenHarmony应用开发-hvigor插件之动态修改应用hap文件名
前端
扑棱蛾子2 小时前
前端代码一键打包上传服务器?10分钟配好永久告别手动部署!
前端·node.js
q***T5832 小时前
前端路由懒加载实现,React与Vue
前端·vue.js·react.js
灵犀坠2 小时前
前端开发核心知识:HTML5特性与经典面试题详解
前端·html·html5
Hilaku2 小时前
我为什么说全栈正在杀死前端?
前端·javascript·后端
YongCheng_Liang2 小时前
ELK 自动化部署脚本解析
linux·运维·elk·jenkins
小白博文2 小时前
MobaXterm调用远程服务器(Linux)图形化界面应用
linux·运维·服务器
8***B3 小时前
前端性能优化插件,图片懒加载与压缩
前端