最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

利用nginx解決cookie跨域訪問的方法

 更新時間:2018年05月11日 14:25:33   作者:孤王就是朕  
本篇文章主要介紹了利用nginx解決cookie跨域訪問的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

一、寫在前面

最近需要把阿里云上的四臺服務器的項目遷移到客戶提供的新的項目中,原來的四臺服務器中用到了一級域名和二級域名。比如aaa.abc.com 和bbb.abc.com 和ccc.abc.com。其中aaa.abc.com登錄,通過把cookie中的信息setDomain給.abc.com。其他系統(tǒng)可以共享這個cookie。但是新的四臺服務器中并沒有申請域名,只有四個ip:

192.168.0.1    單點登錄服務器

192.168.0.2

192.168.0.3

192.168.0.4

因為每臺服務器有兩個項目,都用到單點登錄,所以通過修改新的共享登錄方式花費時間太多,于是在網(wǎng)上搜cookie的跨域登錄,嘗試了下,在192.168.0.1    單點登錄服務器中多次setDomain分別給2、3、4服務器,結(jié)果不理想,因為瀏覽器不允許。后來無意中看到nginx可以通過欺騙的方式共享cookie。于是想到原來公司部署nginx還有這層用法。

二、原來的nginx配置

先說下nginx的安裝,這個網(wǎng)上都有很多教程,不在贅述,我是參照于在Linux里安裝、啟動nginx。需要注意的是./configure后面的各種with,我在配置啟動過程遇到了一些問題:

nginx: [emerg] unknown directive "aio" in

加上--with-file-aio 

復制代碼 代碼如下:
Starting nginx: nginx: [emerg] the INET6 sockets are not supported on this platform in “[::]:80” of the

在后面加上--with-ipv6好使。

安裝完成后。主要是nginx.conf的配置

原來服務器的配置nginx.conf:

# For more information on configuration, see:
#  * Official English Documentation: http://nginx.org/en/docs/
#  * Official Russian Documentation: http://nginx.org/ru/docs/

user root;
worker_processes 2;
worker_cpu_affinity 1000 0100;
error_log logs/error.log;
pid logs/nginx.pid;


events {
  worker_connections 2048;
}

http {
  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;

  gzip on;
  gzip_min_length 1000;
  gzip_buffers   4 8k;
  gzip_types    text/plain application/javascript application/x-javascript text/css application/xml;

  client_max_body_size 8M;
  client_body_buffer_size 128k;

  sendfile      on;
  tcp_nopush     on;
  tcp_nodelay     on;
  keepalive_timeout  65;
  types_hash_max_size 2048;

  include       mime.types;
  default_type    application/octet-stream;

  connection_pool_size 512;
  aio on;
  open_file_cache max=1000 inactive=20s;

  # Load modular configuration files from the /etc/nginx/conf.d directory.
  # See http://nginx.org/en/docs/ngx_core_module.html#include
  # for more information.
  #  主要配置在這里,nginx.conf配置都是一樣
  include /usr/local/nginx/conf/conf.d/*.conf;

  server {
    listen    80 default_server;
    listen [::]:80 ipv6only=on default_server;
    server_name _;
    root     html;

    # Load configuration files for the default server block.
    include /usr/local/nginx/conf/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
      location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
      location = /50x.html {
    }
  }
}

原來服務器的
conf.d/*.conf的配置是reverse-proxy.conf

server
{
  listen 80;
  server_name m.abc.com.cn;
  location / {
    root  /usr/share/nginx/html/;
    index index.html index.htm;
  }
  location ~ \.(jsp|do)?$ {
    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;
    proxy_pass http://localhost:8084;
  }
  if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") { 
        return 403; 
    }
  access_log /home/logs/nginx/m.abc.com.cn_access.log;
}
 
server
{
  listen 80;
  server_name store.abc.com.cn *.store.abc.com.cn;
  location / {
    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;
    proxy_pass http://localhost:8081;
  }
  access_log /home/logs/nginx/store.abc.com.cn_access.log;
}

server
{
  listen 80;
  server_name shopcenter.abc.com.cn;
  location / {
    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;
    proxy_pass http://10.45.100.222:8082;
  }
  access_log /home/logs/nginx/shopcenter.abc.com.cn_access.log;
}
 
server
{
  listen 80;
  server_name search.abc.com.cn;
  location / {
    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;
    proxy_pass http://10.45.100.68:8083;
  }
  access_log /home/logs/nginx/search.abc.com.cn_access.log;
}

以上配置后,nginx啟動后,通過訪問不同的域名來訪問不同服務器。而因為都有二級域名.abc.com.cn。所以可以共享cookie。

nginx的文件結(jié)構(gòu)為:

三、修改后的nginx配置

主要是reverse-proxy.conf 不同

server
{
  listen 9998;
  server_name 192.168.0.1:9998;
  location /servlets/ {
    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;
    proxy_pass http://192.168.0.1:8088;
  }
  location / {

    root  /usr/local/nginx/html/web/;
    index index.html index.htm;
  }
  location ~ \.(jsp|do)?$ {
    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;
    proxy_pass http://192.168.0.1:8088;
    
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout  700s;
  } 
if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") { 
        return 403; 
    }
  access_log /usr/local/nginx/logs/www.abc.com.cn_access.log;
}

server
{
  listen 9994;
  server_name 192.168.0.1:9994;
  location / {
   proxy_redirect off;

    root  /usr/local/nginx/html/weixin/;
    index index.html index.htm;
  }
  location ~ \.(jsp|do)?$ {
    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;
    proxy_pass http://localhost:8084;
  }
  if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") { 
        return 403; 
    }
  access_log /usr/local/nginx/logs/m.abc.com.cn_access.log;
}
 
server
{
  listen 9990;
  server_name store.abc.com.cn *.store.abc.com.cn;
  location / {
    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;
    proxy_pass http://localhost:8081;
  }
  access_log /usr/local/nginx/logs/store.abc.com.cn_access.log;
}

server
{
  listen 9992;
  server_name 192.168.0.1:9992;
  location / {
    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;
    proxy_pass http://192.168.0.2:8082;
  }
  access_log /usr/local/nginx/logs/shopcenter.abc.com.cn_access.log;
}
 
server
{
  listen 9993;
  server_name 192.168.0.1:9993;
  location / {
    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;
    proxy_pass http://192.168.0.3:8083;
  }
  access_log /usr/local/nginx/logs/search.abc.com.cn_access.log;
}

 這樣就可以把192.168.0.1:9998 當做單點服務器,登錄后的domain都為192.168.0.1 。其他的0.2、0.3都可以通過192.168.0.1nginx和單點服務器的不同端口訪問,那么就可以共享這個0.1的域名了。

四、最后

好吧,可能描述的不是那么清楚,有點亂。我所做的工作就是把原來的nginx配置中的端口和域名改成新服務器中的唯一一個ip把這個ip當做那個域名,不同端口對應不同二級域名。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Nginx配置文件(nginx.conf)配置詳解(總結(jié))

    Nginx配置文件(nginx.conf)配置詳解(總結(jié))

    本篇文章主要介紹了Nginx配置文件(nginx.conf)配置詳解,這對初學者有一定的參考價值,有興趣的可以了解一下。
    2016-12-12
  • 使用Nginx作緩存服務器以及刪除其緩存文件的方法

    使用Nginx作緩存服務器以及刪除其緩存文件的方法

    這篇文章主要介紹了使用Nginx作緩存服務器以及刪除其緩存文件的方法,作cache時需要注意一下磁盤的IO瓶頸,需要的朋友可以參考下
    2015-11-11
  • nginx查看連接數(shù)的幾種方法小結(jié)

    nginx查看連接數(shù)的幾種方法小結(jié)

    nginx作為目前最流行的web服務器之一,在許多生產(chǎn)環(huán)境都能看到他的蹤影,有時候,我們需要統(tǒng)計nginx的連接配置,本文主要分享一下如何統(tǒng)計nginx的連接數(shù),需要的朋友可以參考下
    2024-02-02
  • 深入理解nginx的access.log文件

    深入理解nginx的access.log文件

    NGINX軟件會把每個用戶訪問網(wǎng)站的日志記錄到指定的日志文件里,供網(wǎng)站者分析用戶的瀏覽行為,本文主要介紹了nginx的access.log文件,感興趣的可以了解一下
    2023-09-09
  • 教你如何使用 Nginx 進行負載均衡

    教你如何使用 Nginx 進行負載均衡

    Nginx 是一個高性能的 HTTP 和反向代理服務器,它也經(jīng)常被用作郵件代理服務器和通用 TCP/UDP 代理服務器,本文我們將詳細介紹如何使用 Nginx 進行負載均衡,感興趣的朋友跟隨小編一起看看吧
    2024-05-05
  • Nginx負載均衡以及動靜分離的原理與配置

    Nginx負載均衡以及動靜分離的原理與配置

    動靜分離和負載均衡都是配置nginx實現(xiàn)對請求進行操作,所以下面這篇文章主要給大家介紹了關(guān)于Nginx負載均衡以及動靜分離的相關(guān)資料,需要的朋友可以參考下
    2021-06-06
  • Nginx配置四層、七層網(wǎng)絡代理轉(zhuǎn)發(fā)的方法示例

    Nginx配置四層、七層網(wǎng)絡代理轉(zhuǎn)發(fā)的方法示例

    nginx作為透明代理可以充分利用其高性能和靈活性來實現(xiàn)網(wǎng)絡流量的轉(zhuǎn)發(fā)和處理,本文主要介紹了Nginx配置四層、七層網(wǎng)絡代理轉(zhuǎn)發(fā)的方法示例,具有一定的參考價值,感興趣的可以了解一下
    2024-03-03
  • Nginx SSI指令配置詳解

    Nginx SSI指令配置詳解

    這篇文章主要介紹了Nginx SSI指令配置詳解,本文講解了什么是SSI、為什么要用SSI、nginx配置SSI、頁面上配置、配置示例等內(nèi)容,需要的朋友可以參考下
    2015-04-04
  • Nginx安裝配置詳解

    Nginx安裝配置詳解

    Nginx (engine x) 是一個高性能的HTTP和反向代理web服務器,同時也提供了IMAP/POP3/SMTP服務。本文詳細講解了Nginx安裝與配置的方法,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-06-06
  • nginx并發(fā)數(shù)限制limit_conn基本語法

    nginx并發(fā)數(shù)限制limit_conn基本語法

    這篇文章主要為大家介紹了nginx并發(fā)數(shù)限制limit_conn基本語法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-04-04

最新評論

阳曲县| 称多县| 泗洪县| 吴旗县| 正宁县| 乌兰县| 聊城市| 磐安县| 松阳县| 华容县| 湘阴县| 孝昌县| 宾阳县| 乌拉特前旗| 若尔盖县| 永春县| 临漳县| 鹰潭市| 呼图壁县| 双流县| 舞钢市| 泽库县| 本溪市| 门头沟区| 东辽县| 科尔| 区。| 甘孜| 兴安盟| 闻喜县| 菏泽市| 德钦县| 武隆县| 青海省| 吴旗县| 和龙市| 夹江县| 兴国县| 卓资县| 陕西省| 东乡族自治县|