Nginx 配置
多文件Nginx的配置,记录学习
参考文件:https://blog.csdn.net/u011121146/article/details/117284124
https://www.cnblogs.com/flytree/p/15022437.html
https://blog.csdn.net/qq_29678299/article/details/107160509
#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 82; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root D:/Users/Langlang_Tu/Desktop/testAll/sh_energy_v2_js; index login.html; add_header Cache-Control "no-store, no-cache"; # 不缓存 no-store # try_files $uri $uri/ /index.html; # 适配history模式 } location /test { # 精确路径 alias D:/Users/Langlang_Tu/Desktop/testAll/sh_energy_v2_js/test/; index index.html index.html; } location ^~ /electricity/ { # 必须于 / 结尾 alias D:/Users/Langlang_Tu/Desktop/testAll/sh_energy_v2_js/electricity/; index index.html index.html; add_header Cache-Control "no-store, no-cache"; # 不缓存 no-store # 尝试在硬盘中查找文件对应到与location中配置匹配的路径 # 适配history模式 try_files $uri $uri/ D:/Users/Langlang_Tu/Desktop/testAll/sh_energy_v2_js/electricity/index.html; } # location ^~ /electricity/ { # root D:/Users/Langlang_Tu/Desktop/testAll/sh_energy_v2_js; # index index.html index.html; # add_header Cache-Control "no-cache"; # 不缓存 no-store # try_files $uri $uri/ /electricity/index.html; # 适配history模式 # } #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; } #对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件 #因此需要rewrite到index.html中,然后交给路由在处理请求资源 # location @router { # 地址重定向 # rewrite ^.+(?<!js|css|png|map|woff|woff2|png|svg)*$ /electricity/index.html last; # } gzip on; gzip_buffers 32 4K; gzip_comp_level 6; gzip_min_length 200; gzip_types application/javascript text/css text/xml; gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持) gzip_vary on; # 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; #} } server { # 第二端口 vue 测试 listen 8848; server_name localhost; location / { add_header Cache-Control "no-cache"; # 不缓存 no-store root E:/test/vuestudent/dist; index index.html; try_files $uri $uri/ /index.html; # 适配history模式 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } gzip on; gzip_buffers 32 4K; gzip_comp_level 6; gzip_min_length 200; gzip_types application/javascript text/css text/xml; gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持) gzip_vary on; } server { # 第三端口 代码压缩测试 listen 8228; server_name localhost; location / { root D:/Users/langlang_tu/Desktop/testAll/oldSHEnergy/production/sh_energy; index login.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { # 第四端口 测试 listen 4399; server_name localhost; location / { root D:/Users/Langlang_Tu/Desktop/myapps/dist; index index.html; try_files $uri $uri/ /index.html; # 适配history模式 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { # 第五端口 vue 测试 listen 9848; server_name localhost; location / { add_header Cache-Control "no-cache"; # 不缓存 no-store root D:/Users/Langlang_Tu/Desktop/testAll/sh_energy_v2_js/electricity; index index.html; try_files $uri $uri/ /index.html; # 适配history模式 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } gzip on; gzip_buffers 32 4K; gzip_comp_level 6; gzip_min_length 200; gzip_types application/javascript text/css text/xml; gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持) gzip_vary on; } # 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; # } #} }

浙公网安备 33010602011771号