Showing
14 changed files
with
477 additions
and
0 deletions
playbooks/crm-extstore-nginx.yml
0 → 100644
1 | +# crm and extstore nginx | ||
2 | + | ||
3 | +- hosts: crm-store-nginx | ||
4 | + vars_prompt: | ||
5 | + - name: "upstream_az" | ||
6 | + prompt: "Choose which az's upstream: [store_gray_extstore_local|store_local_extstore_local|store_gray_extstore_gray|store_local_extstore_gray] " | ||
7 | + default: 'local' | ||
8 | + private: no | ||
9 | + remote_user: root | ||
10 | + roles: | ||
11 | + - crm.store.nginx |
roles/crm.extstore.nginx/README.md
0 → 100644
1 | +Openresty | ||
2 | +========= | ||
3 | + | ||
4 | +同步 `crm, 线下店 nginx` 的配置文件,并且`reload nginx`. | ||
5 | + | ||
6 | +Requirements | ||
7 | +------------ | ||
8 | + | ||
9 | + - 配置文件目录: `/usr/local/openresty/nginx/conf/nginx.conf` `/usr/local/openresty/nginx/conf/vhosts/` | ||
10 | + - `reload nginx`: ` /usr/local/openresty/nginx/sbin/nginx -s reload` | ||
11 | + | ||
12 | +依赖如下的hosts: | ||
13 | + | ||
14 | + | ||
15 | + | ||
16 | +Author Information | ||
17 | +------------------ | ||
18 | + | ||
19 | +chunhua.zhang@yoho.cn |
roles/crm.extstore.nginx/defaults/main.yml
0 → 100644
1 | +server { | ||
2 | + listen 80; | ||
3 | + server_name adminstore.yohobuy.com adminstore.yohoops.org; | ||
4 | + access_log /Data/logs/nginx/access_adminstore.yobobuy.com.log fenxi; | ||
5 | + location / { | ||
6 | + proxy_redirect off; | ||
7 | + proxy_pass http://yohobuy-adminstore/; | ||
8 | + proxy_set_header Host "adminstore.yohobuy.com"; | ||
9 | + proxy_set_header X-Real-IP $remote_addr; | ||
10 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
11 | + proxy_set_header Accept-Encoding "gzip"; | ||
12 | + client_max_body_size 900m; | ||
13 | + proxy_read_timeout 600s; | ||
14 | + client_body_buffer_size 512k; | ||
15 | + } | ||
16 | +} |
1 | +server{ | ||
2 | + listen 80; | ||
3 | + server_name crmapi.yoho.cn; | ||
4 | + access_log /Data/logs/nginx/access_crmapi.log fenxi; | ||
5 | + | ||
6 | + | ||
7 | + location /crm/AiQiSMSReceiveController { | ||
8 | + deny all; | ||
9 | + proxy_redirect off; | ||
10 | + proxy_pass http://crm_pools/crm/AiQiSMSReceiveController; | ||
11 | + proxy_read_timeout 600s; | ||
12 | + proxy_send_timeout 600s; | ||
13 | + proxy_set_header Host $host; | ||
14 | + proxy_set_header X-Real-IP $http_x_forwarded_for; | ||
15 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
16 | + proxy_set_header Accept-Encoding "gzip"; | ||
17 | + } | ||
18 | + | ||
19 | + | ||
20 | + location /crm/MWSMSReceiveController { | ||
21 | + allow 61.145.229.29; | ||
22 | + allow 112.91.147.37; | ||
23 | + allow 218.204.222.12; | ||
24 | + allow 211.100.48.90; | ||
25 | + allow 218.204.220.242; | ||
26 | + deny all; | ||
27 | + | ||
28 | + proxy_redirect off; | ||
29 | + proxy_pass http://crm_pools/crm/MWSMSReceiveController; | ||
30 | + proxy_read_timeout 600s; | ||
31 | + proxy_send_timeout 600s; | ||
32 | + proxy_set_header Host $host; | ||
33 | + proxy_set_header X-Real-IP $http_x_forwarded_for; | ||
34 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
35 | + proxy_set_header Accept-Encoding "gzip"; | ||
36 | + } | ||
37 | + | ||
38 | + #location / { | ||
39 | + # proxy_redirect off; | ||
40 | + # proxy_read_timeout 600s; | ||
41 | + # proxy_send_timeout 600s; | ||
42 | + # proxy_pass http://crm_pools/crm; | ||
43 | + # proxy_set_header Host $host; | ||
44 | + # proxy_set_header X-Real-IP $http_x_forwarded_for; | ||
45 | + # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
46 | + # proxy_set_header Accept-Encoding "gzip"; | ||
47 | + #} | ||
48 | + | ||
49 | + | ||
50 | +} | ||
51 | + | ||
52 | +server{ | ||
53 | + listen 80; | ||
54 | + | ||
55 | + server_name crm.yoho.cn crm2.yoho.cn; | ||
56 | + access_log /Data/logs/nginx/access_crm.log fenxi; | ||
57 | + | ||
58 | + | ||
59 | + location /crm/ { | ||
60 | + allow 106.39.86.227; | ||
61 | + allow 106.38.38.147; | ||
62 | + allow 106.38.38.146; | ||
63 | + allow 218.94.77.166; | ||
64 | + allow 218.94.75.50; | ||
65 | + allow 218.94.75.58; | ||
66 | + allow 180.169.239.138; | ||
67 | + deny all; | ||
68 | + proxy_redirect off; | ||
69 | + proxy_pass http://crm_pools/crm/; | ||
70 | + proxy_read_timeout 600s; | ||
71 | + proxy_send_timeout 600s; | ||
72 | + proxy_set_header Host $host; | ||
73 | + proxy_set_header X-Real-IP $http_x_forwarded_for; | ||
74 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
75 | + proxy_set_header Accept-Encoding "gzip"; | ||
76 | + } | ||
77 | + | ||
78 | + location / { | ||
79 | + allow 106.39.86.227; | ||
80 | + allow 106.38.38.147; | ||
81 | + allow 106.38.38.146; | ||
82 | + allow 218.94.77.166; | ||
83 | + allow 218.94.75.50; | ||
84 | + allow 218.94.75.58; | ||
85 | + allow 180.169.239.138; | ||
86 | + deny all; | ||
87 | + proxy_redirect off; | ||
88 | + proxy_read_timeout 600s; | ||
89 | + proxy_send_timeout 600s; | ||
90 | + proxy_pass http://crm_pools/crm; | ||
91 | + proxy_set_header Host $host; | ||
92 | + proxy_set_header X-Real-IP $http_x_forwarded_for; | ||
93 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
94 | + proxy_set_header Accept-Encoding "gzip"; | ||
95 | + } | ||
96 | + | ||
97 | + | ||
98 | +} | ||
99 | + |
1 | +server { | ||
2 | + listen 80; | ||
3 | + server_name extstore.yohobuy.com extstore.test.yohobuy.com; | ||
4 | + #charset koi8-r; | ||
5 | + access_log /Data/logs/nginx/access_extstore.yohobuy.com.log fenxi; | ||
6 | + | ||
7 | + location / { | ||
8 | + proxy_redirect off; | ||
9 | + proxy_pass http://extstore/extendstore/; | ||
10 | + proxy_set_header Host "extstore.yohobuy.com"; | ||
11 | + proxy_set_header X-Real-IP $remote_addr; | ||
12 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
13 | + proxy_set_header Accept-Encoding "gzip"; | ||
14 | + } | ||
15 | +} |
1 | +server { | ||
2 | + listen 80; | ||
3 | + server_name o.yohobuy.com; | ||
4 | + #charset koi8-r; | ||
5 | + access_log /Data/logs/nginx/access_openstore.yohobuy.com.log fenxi; | ||
6 | + | ||
7 | + location / { | ||
8 | + proxy_redirect off; | ||
9 | + proxy_pass http://portal-gateway/portal-gateway/qrcode/; | ||
10 | + proxy_set_header Host "portal-gateway.yohobuy.com"; | ||
11 | + proxy_set_header X-Real-IP $remote_addr; | ||
12 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
13 | + proxy_set_header Accept-Encoding "gzip"; | ||
14 | + } | ||
15 | +} | ||
16 | + | ||
17 | +server { | ||
18 | + listen 80; | ||
19 | + server_name openstore.yohobuy.com ; | ||
20 | + #charset koi8-r; | ||
21 | + access_log /Data/logs/nginx/access_openstore.yohobuy.com.log fenxi; | ||
22 | + | ||
23 | + location / { | ||
24 | + proxy_redirect off; | ||
25 | + proxy_pass http://portal-gateway/portal-gateway/wechat/; | ||
26 | + proxy_set_header Host "portal-gateway.yohobuy.com"; | ||
27 | + proxy_set_header X-Real-IP $remote_addr; | ||
28 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
29 | + proxy_set_header Accept-Encoding "gzip"; | ||
30 | + } | ||
31 | +} | ||
32 | + | ||
33 | +server { | ||
34 | + listen 80; | ||
35 | + server_name instore.yohobuy.com; | ||
36 | + #charset koi8-r; | ||
37 | + access_log /Data/logs/nginx/access_instore.yohobuy.com.log fenxi; | ||
38 | + | ||
39 | + location / { | ||
40 | + proxy_redirect off; | ||
41 | + proxy_pass http://portal-gateway/portal-gateway/api/; | ||
42 | + proxy_set_header Host "instore.yohobuy.com"; | ||
43 | + proxy_set_header X-Real-IP $remote_addr; | ||
44 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
45 | + proxy_set_header Accept-Encoding "gzip"; | ||
46 | + } | ||
47 | +} | ||
48 | + | ||
49 | +server { | ||
50 | + listen 80; | ||
51 | + server_name api.store.yohoops.org; | ||
52 | + #charset koi8-r; | ||
53 | + access_log /Data/logs/nginx/access_api.store.yohoops.org.log fenxi; | ||
54 | + | ||
55 | + location / { | ||
56 | + proxy_redirect off; | ||
57 | + proxy_pass http://portal-gateway/portal-gateway/erp/; | ||
58 | + #proxy_pass http://yohobuy-platform-gray/platform/; | ||
59 | + proxy_set_header Host "api.store.yohoops.org"; | ||
60 | + proxy_set_header X-Real-IP $remote_addr; | ||
61 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
62 | + proxy_set_header Accept-Encoding "gzip"; | ||
63 | + } | ||
64 | + | ||
65 | +} | ||
66 | + |
roles/crm.extstore.nginx/handlers/main.yml
0 → 100644
roles/crm.extstore.nginx/meta/main.yml
0 → 100644
1 | +galaxy_info: | ||
2 | + author: chunhua.zhang@yoho.cn | ||
3 | + description: update java openresty config | ||
4 | + company: yohobuy.com | ||
5 | + | ||
6 | + # If the issue tracker for your role is not on github, uncomment the | ||
7 | + # next line and provide a value | ||
8 | + # issue_tracker_url: http://example.com/issue/tracker | ||
9 | + | ||
10 | + # Some suggested licenses: | ||
11 | + # - BSD (default) | ||
12 | + # - MIT | ||
13 | + # - GPLv2 | ||
14 | + # - GPLv3 | ||
15 | + # - Apache | ||
16 | + # - CC-BY | ||
17 | + license: license (GPLv2, CC-BY, etc) | ||
18 | + | ||
19 | + min_ansible_version: 1.2 | ||
20 | + | ||
21 | + # If this a Container Enabled role, provide the minimum Ansible Container version. | ||
22 | + # min_ansible_container_version: | ||
23 | + | ||
24 | + # Optionally specify the branch Galaxy will use when accessing the GitHub | ||
25 | + # repo for this role. During role install, if no tags are available, | ||
26 | + # Galaxy will use this branch. During import Galaxy will access files on | ||
27 | + # this branch. If Travis integration is configured, only notifications for this | ||
28 | + # branch will be accepted. Otherwise, in all cases, the repo's default branch | ||
29 | + # (usually master) will be used. | ||
30 | + #github_branch: | ||
31 | + | ||
32 | + # | ||
33 | + # platforms is a list of platforms, and each platform has a name and a list of versions. | ||
34 | + # | ||
35 | + # platforms: | ||
36 | + # - name: Fedora | ||
37 | + # versions: | ||
38 | + # - all | ||
39 | + # - 25 | ||
40 | + # - name: SomePlatform | ||
41 | + # versions: | ||
42 | + # - all | ||
43 | + # - 1.0 | ||
44 | + # - 7 | ||
45 | + # - 99.99 | ||
46 | + | ||
47 | + galaxy_tags: [] | ||
48 | + # List tags for your role here, one per line. A tag is a keyword that describes | ||
49 | + # and categorizes the role. Users find roles by searching for tags. Be sure to | ||
50 | + # remove the '[]' above, if you add tags to this list. | ||
51 | + # | ||
52 | + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. | ||
53 | + # Maximum 20 tags per role. | ||
54 | + | ||
55 | +dependencies: [] | ||
56 | + # List your role dependencies here, one per line. Be sure to remove the '[]' above, | ||
57 | + # if you add dependencies to this list. |
roles/crm.extstore.nginx/tasks/main.yml
0 → 100644
1 | +--- | ||
2 | +# tasks file for openresty | ||
3 | + | ||
4 | +# make sure path exist | ||
5 | +- stat: | ||
6 | + path: "{{ path }}" | ||
7 | + register: stat_result | ||
8 | +- name: "make sure openresty path exist" | ||
9 | + fail: | ||
10 | + msg: " openresty {{ path }} not exist!" | ||
11 | + when: stat_result.stat.exists == False | ||
12 | + | ||
13 | + | ||
14 | + | ||
15 | +# make sure group exists | ||
16 | +- name: make sure groups exist in inventory file | ||
17 | + fail: | ||
18 | + msg: "group {{ item }} not exist!" | ||
19 | + when: item not in groups | ||
20 | + with_items: | ||
21 | + - crm-store-nginx | ||
22 | + - java-shops | ||
23 | + - java-portal-gateway | ||
24 | + - java-extendstore | ||
25 | + - java-crm | ||
26 | + | ||
27 | +- name: copy vhosts conf files to openresty | ||
28 | + copy: | ||
29 | + src: vhosts/ | ||
30 | + dest: "{{ path }}/nginx/conf/vhosts" | ||
31 | + notify: | ||
32 | + - reload nginx | ||
33 | + | ||
34 | + | ||
35 | +- name: update nginx upstream for nginx.conf | ||
36 | + template: | ||
37 | + src: nginx.conf.j2 | ||
38 | + dest: "{{ path }}/nginx/conf/nginx.conf" | ||
39 | + notify: | ||
40 | + - reload nginx |
1 | +worker_processes 4; | ||
2 | +worker_cpu_affinity 00000001 00000010 00000100 00001000; | ||
3 | + | ||
4 | +pid /usr/local/openresty/nginx/logs/nginx.pid; | ||
5 | +error_log /Data/logs/nginx/nginx_error.log; | ||
6 | +worker_rlimit_nofile 51200; | ||
7 | + | ||
8 | +events | ||
9 | +{ | ||
10 | + use epoll; | ||
11 | + worker_connections 51200; | ||
12 | +} | ||
13 | + | ||
14 | +http | ||
15 | +{ | ||
16 | + include /usr/local/openresty/nginx/conf/mime.types; | ||
17 | + default_type application/octet-stream; | ||
18 | + #charset gb2312,utf-8; | ||
19 | + charset utf-8; | ||
20 | + | ||
21 | + | ||
22 | + log_format fenxi '$remote_addr|$http_x_forwarded_for|[$time_local]|$http_host|$request|' | ||
23 | + '$status|$body_bytes_sent|$request_time|$upstream_response_time|$upstream_cache_status|$http_referer|' | ||
24 | + '$upstream_addr|$http_user_agent'; | ||
25 | + | ||
26 | + #General Options | ||
27 | + server_names_hash_bucket_size 128; | ||
28 | + client_header_buffer_size 32k; | ||
29 | + large_client_header_buffers 4 32k; | ||
30 | + client_body_buffer_size 8m; #256k | ||
31 | + #server_tokens off; | ||
32 | + #ignore_invalid_headers on; | ||
33 | + #recursive_error_pages on; | ||
34 | + server_name_in_redirect off; | ||
35 | + | ||
36 | + sendfile on; | ||
37 | + | ||
38 | + #timeouts | ||
39 | + keepalive_timeout 180; | ||
40 | + keepalive_requests 1000; | ||
41 | + | ||
42 | + | ||
43 | + #TCP Options | ||
44 | + tcp_nopush on; | ||
45 | + tcp_nodelay on; | ||
46 | + | ||
47 | + send_timeout 120s; | ||
48 | + | ||
49 | + #fastcgi options | ||
50 | + fastcgi_connect_timeout 300; | ||
51 | + fastcgi_send_timeout 300; | ||
52 | + fastcgi_read_timeout 300; | ||
53 | + fastcgi_buffer_size 64k; | ||
54 | + fastcgi_buffers 8 128k; | ||
55 | + fastcgi_busy_buffers_size 128k; | ||
56 | + fastcgi_temp_file_write_size 128k; | ||
57 | + | ||
58 | + #size limits | ||
59 | + client_max_body_size 900m; | ||
60 | + | ||
61 | + gzip on; | ||
62 | + gzip_min_length 1k; | ||
63 | + gzip_buffers 4 16k; | ||
64 | + gzip_http_version 1.0; | ||
65 | + gzip_comp_level 2; | ||
66 | + gzip_types text/plain application/x-javascript text/css application/xml; | ||
67 | + gzip_vary on; | ||
68 | + | ||
69 | + proxy_temp_path /usr/local/openresty/nginx/ngx_temp_dir; | ||
70 | + proxy_cache_path /usr/local/openresty/nginx/ngx_cache levels=1:2 keys_zone=cache_one:500m inactive=1d max_size=10g; | ||
71 | + proxy_connect_timeout 120s; | ||
72 | + proxy_read_timeout 300s; | ||
73 | + proxy_buffer_size 16k; | ||
74 | + proxy_buffers 4 64k; | ||
75 | + proxy_busy_buffers_size 128k; | ||
76 | + proxy_temp_file_write_size 128k; | ||
77 | + | ||
78 | + fastcgi_temp_path /dev/shm/fastcgi_temp; | ||
79 | + client_body_temp_path /dev/shm/client_body_temp; | ||
80 | + | ||
81 | + upstream crm_pools { | ||
82 | + {% for i in groups['java-crm'] %} | ||
83 | + server {{ i }}:8093 max_fails=5 fail_timeout=30s; | ||
84 | + {% endfor %} | ||
85 | + } | ||
86 | + | ||
87 | + upstream portal-gateway { | ||
88 | + {% if upstream_az == 'store_gray_extstore_local' %} | ||
89 | + server 10.66.101.10:8080 max_fails=5 fail_timeout=30s; | ||
90 | + {% elif upstream_az == 'store_local_extstore_local' %} | ||
91 | + {% for i in groups['java-portal-gateway'] %} | ||
92 | + server {{ i }}:8080 max_fails=5 fail_timeout=30s; | ||
93 | + {% endfor %} | ||
94 | + {% elif upstream_az == 'store_gray_extstore_gray' %} | ||
95 | + server 10.66.101.10:8080 max_fails=5 fail_timeout=30s; | ||
96 | + {% else %} | ||
97 | + {% for i in groups['java-portal-gateway'] %} | ||
98 | + server {{ i }}:8080 max_fails=5 fail_timeout=30s; | ||
99 | + {% endfor %} | ||
100 | + {% endif %} | ||
101 | + } | ||
102 | + | ||
103 | + upstream yohobuy-adminstore { | ||
104 | + {% for i in groups['java-shops'] %} | ||
105 | + server {{ i }}:8098 max_fails=5 fail_timeout=30s; | ||
106 | + {% endfor %} | ||
107 | + } | ||
108 | + | ||
109 | + | ||
110 | + upstream extstore { | ||
111 | + {% if upstream_az == 'store_gray_extstore_local' %} | ||
112 | + {% for i in groups['java-extendstore'] %} | ||
113 | + server {{ i }}:8094 max_fails=5 fail_timeout=30s; | ||
114 | + {% endfor %} | ||
115 | + {% elif upstream_az == 'store_local_extstore_local' %} | ||
116 | + {% for i in groups['java-extendstore'] %} | ||
117 | + server {{ i }}:8094 max_fails=5 fail_timeout=30s; | ||
118 | + {% endfor %} | ||
119 | + {% elif upstream_az == 'store_gray_extstore_gray' %} | ||
120 | + server 10.66.101.10:8094 max_fails=5 fail_timeout=30s; | ||
121 | + {% else %} | ||
122 | + server 10.66.101.10:8094 max_fails=5 fail_timeout=30s; | ||
123 | + {% endif %} | ||
124 | + } | ||
125 | + | ||
126 | + include vhosts/crm.conf; | ||
127 | + include vhosts/extstore.conf; | ||
128 | + include vhosts/shop.conf; | ||
129 | + include vhosts/adminstore.yohobuy.conf; | ||
130 | +} | ||
131 | + |
roles/crm.extstore.nginx/tests/inventory
0 → 100644
roles/crm.extstore.nginx/tests/test.yml
0 → 100644
roles/crm.extstore.nginx/vars/main.yml
0 → 100644
-
Please register or login to post a comment