漂泊雪狼的博客

思考,讨论,分享C#,JavaScript,.NET,Oracle,SQL Server……技术

导航

Nginx跨域配置方法

Posted on 2016-12-02 15:55  漂泊雪狼  阅读(776)  评论(0编辑  收藏  举报

配置文件如下,重点在49~52行

  1 #user  nobody;
  2 worker_processes  1;
  3 
  4 #error_log  logs/error.log;
  5 #error_log  logs/error.log  notice;
  6 #error_log  logs/error.log  info;
  7 
  8 #pid        logs/nginx.pid;
  9 
 10 
 11 events {
 12     worker_connections  1024;
 13 }
 14 
 15 
 16 http {
 17     include       mime.types;
 18     default_type  application/octet-stream;
 19 
 20     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 21     #                  '$status $body_bytes_sent "$http_referer" '
 22     #                  '"$http_user_agent" "$http_x_forwarded_for"';
 23 
 24     #access_log  logs/access.log  main;
 25 
 26     sendfile        on;
 27     #tcp_nopush     on;
 28 
 29     #keepalive_timeout  0;
 30     keepalive_timeout  65;
 31 
 32     #gzip  on;
 33 
 34     server {
 35         listen       88;
 36         server_name  localhost;
 37 
 38         #charset koi8-r;
 39 
 40         #access_log  logs/host.access.log  main;
 41 
 42 
 43 
 44         location / {
 45             root   web;
 46             index  index.html index.htm;
 47         }
 48 
 49 location ^~/proxy/html/{
 50 rewrite ^/proxy/html/(.*)$ /$1 break;
 51 #root proxy;
 52 proxy_pass http://localhost:81;
 53 }
 54         #error_page  404              /404.html;
 55 
 56         # redirect server error pages to the static page /50x.html
 57         #
 58         error_page   500 502 503 504  /50x.html;
 59         location = /50x.html {
 60             root   html;
 61         }
 62 
 63         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 64         #
 65         #location ~ \.php$ {
 66         #    proxy_pass   http://127.0.0.1;
 67         #}
 68 
 69         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 70         #
 71         #location ~ \.php$ {
 72         #    root           html;
 73         #    fastcgi_pass   127.0.0.1:9000;
 74         #    fastcgi_index  index.php;
 75         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 76         #    include        fastcgi_params;
 77         #}
 78 
 79         # deny access to .htaccess files, if Apache's document root
 80         # concurs with nginx's one
 81         #
 82         #location ~ /\.ht {
 83         #    deny  all;
 84         #}
 85     }
 86 
 87 
 88     # another virtual host using mix of IP-, name-, and port-based configuration
 89     #
 90     #server {
 91     #    listen       8000;
 92     #    listen       somename:8080;
 93     #    server_name  somename  alias  another.alias;
 94 
 95     #    location / {
 96     #        root   html;
 97     #        index  index.html index.htm;
 98     #    }
 99     #}
100 
101 
102     # HTTPS server
103     #
104     #server {
105     #    listen       443 ssl;
106     #    server_name  localhost;
107 
108     #    ssl_certificate      cert.pem;
109     #    ssl_certificate_key  cert.key;
110 
111     #    ssl_session_cache    shared:SSL:1m;
112     #    ssl_session_timeout  5m;
113 
114     #    ssl_ciphers  HIGH:!aNULL:!MD5;
115     #    ssl_prefer_server_ciphers  on;
116 
117     #    location / {
118     #        root   html;
119     #        index  index.html index.htm;
120     #    }
121     #}
122 
123 }