轻设计 / 轻生活 / 轻日记 / 轻梦想
=== zhoumojianshe ===
项目要求访问路径为:http://ip:端口/index.html
1、windows配置方法 【windows用8083端口为例】
server { listen 8083; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #非根目录访问配置方法 #location /web { # alias html/web; #} location / { root 'D:\\nginx-1.13.5\\nginx-1.13.5\\html\\web'; index index.html; autoindex on; } location /mc/{ add_header 'Access-Control-Allow-Origin' "$http_origin"; add_header 'Access-Control-Allow-Credentials' "true"; add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive, User-Agent,X-Requested-With,If-Modified-Since, Cache-Control,Content-Type,Authorization,token'; add_header 'Access-Control-Allow-Methods' 'POST, GET, OPTIONS'; 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://8.61.160.88:8091; } }
页面访问地址
<script> jQuery.ajax({ url: "http://localhost:8083/mc/article/ getArticleDetail.action?id=E9B0F451-F092-41AC-B3BE-1629A11E3DA1", async: false, data: {}, type: 'get', dataType: 'json', beforeSend: function () { //alert(action); }, success: function (o) { // 可添加预处理 //alert(JSON.stringify(o)); $("#dd").html(o.data.artcontent); }, complete: function (XMLHttpRequest, textStatus) { //alert('ss2'); }, error: function (XMLHttpRequest, textStatus, errorThrown) { //alert(XMLHttpRequest.status); //alert(XMLHttpRequest.readyState); //alert(textStatus); } }); </script>
2、Linux配置方法【linux用80端口为例】
server { listen 80 default_server; listen [::]:80 default_server; server_name _; #charset koi8-r; #access_log logs/host.access.log main; add_header Cache-Control no-cache; add_header Cache-Control private; location / { root /usr/local/web/dist; index index.html index.htm; } location /mc/{ add_header 'Access-Control-Allow-Origin' "$http_origin"; add_header 'Access-Control-Allow-Credentials' "true"; add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent, X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,token'; add_header 'Access-Control-Allow-Methods' 'POST, GET, OPTIONS'; 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://8.61.160.88:8091; } }
页面访问地址
<script>
jQuery.ajax({
url: "http://8.61.160.88/mc/article/
getArticleDetail.action?
id=E9B0F451-F092-41AC-B3BE-1629A11E3DA1",
async: false,
data: {},
type: 'get',
dataType: 'json',
beforeSend: function () {
//alert(action);
},
success: function (o) {
// 可添加预处理
//alert(JSON.stringify(o));
$("#dd").html(o.data.artcontent);
},
complete: function (XMLHttpRequest, textStatus) {
//alert('ss2');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
//alert(XMLHttpRequest.status);
//alert(XMLHttpRequest.readyState);
//alert(textStatus);
}
});
</script>
本文由周末简设原创出品,如需转载请注明出处
本文出处:http://www.youtiy.com/detail_613.html