nginx配置访问index主页

一 背景

  我们在做一个网站或者是一个网页的时候,一个通常的做法是当输入网站或者网页的域名xxxxx.com的时候就可以访问网站的主页。那么一个比较好的方法就是在nginx中进行配置。那么接下来我们就来讨论一下这个问题。

二 解决方法

在nginx中应当如何进行配置呢?

server {

listen 80;

server_name xxxxx.com;

access_log /data/log/nginx/browser-in_access.log main;



location ~* .*\.svn.* {

return 404;

}

location ^~ /v1/ {

return 204;

}


#网站主页

location / {

root /data/static/resources/browser-intl/20180719/views;

index index.html;

}





location ^~ /chrome_custom/ {

proxy_store off;

proxy_redirect off;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header Host $http_host;

proxy_pass http://localhost:8080/chrome_custom/;

}

location ^~ /static/ {

proxy_store off;

proxy_redirect off;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header Host $http_host;



proxy_ignore_headers Expires Set-Cookie;

proxy_cache cache_one;

proxy_cache_valid 200 304 2m;

proxy_cache_key $scheme$proxy_host$request_uri;

add_header X-Proxy-Cache $upstream_cache_status;

expires 10m;

proxy_pass http://localhost:8080/static/;

}

#比较简陋的做法.当访问主页的时候,可能会出现的情况是只显示html,但是css,image,js等等都#是无法显示的。原因可能就是#css,image,js等资源的路径是不正确的。

location /images {

alias /data/static/resources/browser-intl/20180719/images;

}

location /css {

alias /data/static/resources/browser-intl/20180719/css;

}

location /js {

alias /data/static/resources/browser-intl/20180719/js;

}

location /json {

alias /data/static/resources/browser-intl/20180719/json;

}

}



server {

listen 443;

access_log /data/log/nginx/browser-in-ssl_access.log main;

server_name xxxxxxx.com;

ssl on;

ssl_certificate xxxxxxxxxx

ssl_certificate_key xxxxxxxxxxxxxxxx;

ssl_session_timeout 5m;

ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-RSA-RC4-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:ECDHE-RSA-AES128-SHA256:RC4-SHA:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!DSS:!PKS;

ssl_prefer_server_ciphers on;



location ~* .*\.svn.* {

return 404;

}



location ^~ /v1/ {

return 204;

}

location / {

root /data/static/resources/browser-intl/20180719/views;

index index.html;

}





location ^~ /chrome_custom/ {

proxy_store off;

proxy_redirect off;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header Host $http_host;

proxy_pass http://localhost:8080/chrome_custom/;

}



location ^~ /static/ {

proxy_store off;

proxy_redirect off;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header Host $http_host;



proxy_ignore_headers Expires Set-Cookie;

proxy_cache cache_one;

proxy_cache_valid 200 304 2m;

proxy_cache_key $scheme$proxy_host$request_uri;

add_header X-Proxy-Cache $upstream_cache_status;

expires 10m;



proxy_pass https://localhost:8080/static/;

}



location /static/black_white_list/listMulti {

return 404;

}

location /static/bloom_config/listAll {

return 404;

}

location /images {

alias /data/static/resources/browser-intl/20180719/images;

}



location /css {

alias /data/static/resources/browser-intl/20180719/css;

}



location /js {

alias /data/static/resources/browser-intl/20180719/js;

}



location /json {

alias /data/static/resources/browser-intl/20180719/json;

}

}

三 :总结

多动脑筋。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱coding的同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值