[英]nginx to cdn or node.js
我有一个运行ngnix的简单示例,该示例代理了我在localhost:3001上运行的node.js应用程序。 现在,我要添加一些优化,问题是我不确定我是否完全了解ngnix配置文件的工作方式。
我要做的是通过ngnix的代理转发从CDN提供index.html,about.html和main.js。 我想我需要为这两个文件(以及最终整个图像和CSS目录)添加类似重写的内容
因此,用户转到mydomain.com。.ngnix进入并从cdn.mydomain.com/index.html提供index.html。
这是我现在所拥有的:
===================
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
send_timeout 600;
proxy_buffering off;
####
# the IP(s) on which your node server is running i choose the port 3001
upstream app_yourdomian {
server 127.0.0.1:3001;
}
# the nginx server instance
server {
listen 0.0.0.0:80;
server_name ec2-75-101-203-200.compute-1.amazonaws.com ec2-75-101-203-200.compute-1.amazonaws;
access_log /var/log/nginx/yourdomain.log;
# pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:3001;
proxy_redirect off;
}
}
===========================
如果您真的需要代理(而不是重定向到)about和main.js索引,那么就像上述每个地方都有三个简单的位置
location = /index.html {proxy_pass ...}
您可能还想看看http://wiki.nginx.org/HttpCoreModule#location
对于没有正则表达式的位置,使用最具体的匹配项。
随时在邮件列表中询问更多信息http://mailman.nginx.org/mailman/listinfo/nginx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.