轻设计 / 轻生活 / 轻日记 / 轻梦想 === zhoumojianshe ===
© 优特良品&优特建站出品 | Powered by YOUTIY
苏ICP备13018047号-1
Nginx 根路径访问配置
TAGS: 后端设计

项目要求访问路径为: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

周末
2021-11-26 11:35:42
标签云
网页设计 精致慢生活 感悟思语 我的旧年华
加偶微信