# nginx在windows下安装
地址 (opens new window) 把nginx.exe地址配置在环境变量之中
- 直接双击nginx.exe,双击后一个黑色的弹窗一闪而过
- 打开cmd命令窗口,切换到nginx解压目录下,输入命令
nginx.exe或者start nginx,回车即可 - 检查nginx是否启动成功,直接在浏览器地址栏输入网址 http://localhost:80,回车,出现欢迎页面即为成功
- 停止
nginx.exe -s stop或nginx.exe -s quit
# 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;
server {
listen 8087;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/html-test;
index index.html;
}
location /api/{
proxy_pass http://localhost:5000;
proxy_set_header HOST $host;
}
#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;
}
}
}
server中通过将静态文件放在nginx中的html中,而后台服务用proxy_pass配置location实现跨域.
- 请求的地址通过反向代理都被代理到同一个端口下,实现跨域,请求的url使用的这个server的端口
- cors则是放行了某些跨域请求,所以请求的url用的还是后端程序api端口
# 其他问题
1.当前目录即为根目录,nginx./图片403,但是/显示图片。是否是配置的问题?本地查看一切正常。而且部署在nginx后,感觉图层的z-index似乎也发生了变化.
- html目录存放静态文件
- nginx.conf配置
- sbin/nginx -s reload 重启nginx
← nginx