广告
返回顶部
首页 > 资讯 > 精选 >怎么在nginx中解决cookie跨域访问问题
  • 614
分享到

怎么在nginx中解决cookie跨域访问问题

2023-06-08 00:06:46 614人浏览 薄情痞子
摘要

怎么在Nginx中解决cookie跨域访问问题?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。1nginx: [emerg] unknown directive

怎么在Nginx中解决cookie跨域访问问题?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

1

nginx: [emerg] unknown directive "aio" in

加上--with-file-ai

复制代码 代码如下:

Starting nginx: nginx: [emerg] the INET6 Sockets are not supported on this platfORM in “[::]:80” of the

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

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

原来服务器的配置nginx.conf:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

# 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

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

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的文件结构为:

怎么在nginx中解决cookie跨域访问问题

三、修改后的nginx配置

主要是reverse-proxy.conf 不同

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

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的域名了。

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注编程网精选频道,感谢您对编程网的支持。

http://www.cnblogs.com/minzhousblogs/p/9023391.html

--结束END--

本文标题: 怎么在nginx中解决cookie跨域访问问题

本文链接: https://www.lsjlt.com/news/250501.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 怎么在nginx中解决cookie跨域访问问题
    怎么在nginx中解决cookie跨域访问问题?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。1nginx: [emerg] unknown directive ...
    99+
    2023-06-08
  • Nginx解决跨域问题
    目录 前言 一、跨域问题 1.什么是跨域  2.CORS 二、Nginx跨域处理 三.补充 前言 这几天出现了一个问题,我们中的一个A系统需要给B系统调用,造成了跨域问题。 一、跨域问题 1.什么是跨域 当一个请求url的协议、域...
    99+
    2023-09-02
    nginx 服务器 开发语言
  • 如何解决Ajax跨域访问Cookie丢失问题
    这篇文章将为大家详细讲解有关如何解决Ajax跨域访问Cookie丢失问题,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1.ajax跨域访问,cookie丢失首先创建两个测...
    99+
    2022-10-19
  • JSONP怎么解决Ajax跨域访问问题
    这篇文章主要介绍“JSONP怎么解决Ajax跨域访问问题”,在日常操作中,相信很多人在JSONP怎么解决Ajax跨域访问问题问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”JS...
    99+
    2022-10-19
  • 解决nginx/apache静态资源跨域访问问题详解
    1. apache静态资源跨域访问 找到apache配置文件httpd.conf 找到这行 #LoadModule headers_module modules/mod_headers.so 把#注释符去掉 Load...
    99+
    2022-06-04
    nginx 跨域访问 apache 跨域访问 静态资源跨域访问
  • 使用Nginx解决跨域问题
    目录 使用Nginx解决跨域问题 1、修改浏览器、客户端访问地址 2、在nginx.conf配置文件需配置server 3、在Nginx中配置客户端访问的接口(按照规则或通配),并设置被代理的服务器 4、在Nginx中统一配置客户端访问的...
    99+
    2023-09-02
    nginx 运维 服务器
  • Nginx跨域问题解析与解决
    目录什么是跨域跨域场景解决跨域的四种方式什么是跨域 域: 是指浏览器不能执行其他网站的脚本跨域: 它是由浏览器的 同源策略 造成的,是浏览器对 JavaScript 实施的安全限制,...
    99+
    2022-11-13
    Nginx 跨域 Nginx 跨域问题
  • nginx 配置解决前端跨域问题
    一、为什么会出现跨域问题        出于浏览器的同源策略限制。同源策略(Sameoriginpolicy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响。可以说Web是构建在同源策...
    99+
    2023-09-10
    前端 nginx 服务器
  • Nginx配置解决NetCore的跨域问题
    使用Nginx配置解决NetCore的跨域 废话不多说,直接上Nginx配置 server { listen 80; server_name 你的Id或域名;...
    99+
    2022-11-13
  • php、apache、nginx如何解决跨域问题
    这篇文章给大家分享的是有关php、apache、nginx如何解决跨域问题的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。apache:a. 首先确保加载了mod_headers模...
    99+
    2022-10-19
  • 怎么解决ajax跨域问题
    本篇内容主要讲解“怎么解决ajax跨域问题”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么解决ajax跨域问题”吧!什么是ajax跨域ajax跨域的原理aja...
    99+
    2022-10-19
  • vue2.0跨域问题怎么解决
    本篇内容主要讲解“vue2.0跨域问题怎么解决”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“vue2.0跨域问题怎么解决”吧! 一种解决方案: 一般的情况下...
    99+
    2022-10-19
  • javascript怎么解决跨域问题
    这篇文章主要介绍了javascript怎么解决跨域问题,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。javascript 跨域问题以及解决办...
    99+
    2022-10-19
  • vue跨域问题怎么解决
    1、可以在后端服务器中进行配置,允许指定的域名或IP地址访问后端API,这样就可以解决跨域问题。常用的方法是在服务器端添加CORS(...
    99+
    2023-05-13
    vue跨域问题 vue
  • ajax跨域问题怎么解决
    在Ajax请求中,由于浏览器的同源策略限制,如果请求的域名、端口或协议与当前页面不同,则会出现跨域问题,无法正常获取数据。以下是几种...
    99+
    2023-05-13
    ajax跨域问题 ajax
  • react跨域问题怎么解决
    在 React 中解决跨域问题通常有以下几种方法:1. 设置代理:在开发环境中,可以通过设置代理服务器来解决跨域问题。可以在 `pa...
    99+
    2023-08-19
    react
  • springboot怎么解决跨域问题
    在Spring Boot中解决跨域问题可以通过以下几种方式: 使用注解@EnableWebMvc和@CrossOrigin:在S...
    99+
    2023-10-25
    springboot
  • 怎么解决WebSocket跨域问题
    怎么解决WebSocket跨域问题?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。WebSocket通信是点对点:一是建立WebSocket链接的URL加上时间戳保证通信会话是唯...
    99+
    2023-06-09
  • JavaScript跨域问题怎么解决
    这篇文章主要介绍了JavaScript跨域问题怎么解决的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇JavaScript跨域问题怎么解决文章都会有所收获,下面我们一起来看看吧。1.什么是跨域我们常常会在页面上使...
    99+
    2023-06-27
  • 怎么解决SpringBoot跨域问题
    这篇文章给大家分享的是有关怎么解决SpringBoot跨域问题的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。允许全部请求跨域许可的代码需要继承WebMvcConfigurerAdapter类。@Configura...
    99+
    2023-06-28
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作