一 背景
我们在做一个网站或者是一个网页的时候,一个通常的做法是当输入网站或者网页的域名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;
}
}
三 :总结
多动脑筋。