需求
我有几个html,css,js文件,需要本地启动nginx访问,以前觉得很简单,但是踩了一些坑之后,做个记录
nginx完整配置
#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;
upstream manage{
server localhost:8765;
}
server {
listen 8765;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index debug-all.html index.html;
}
location /vision-push {
root D:\jar;
index debug-all.html index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
访问
http://localhost:8765/vision-push/
使用root的配置的说明
原始文件在D:\jar\vision-push2/debug-all.html下
访问地址:http://localhost:8765/vision-push2
nginx拼接地址:D:\jar\vision-push,会把vision-push带上
location /vision-push {
root D:\jar;
index debug-all.html index.html;
}
使用alias配置说明
原始文件在D:\jar\vision-push2/debug-all.html下
访问地址:http://localhost:8765/vision-push
nginx拼接地址:D:\jar\vision-push,会把vision-push带上
location /vision-push {
alias D:\jar\vision-push;
index debug-all.html index.html;
}
root和alias完整对比
location /vision-push {
root D:\jar;
index debug-all.html index.html;
}
location /vision-push {
alias D:\jar\vision-push;
index debug-all.html index.html;
}