nginx通过https和http提供静态文件
所以,我只想保护我的网站的登录和管理部分。问题是管理员使用了一些常用的静态文件,这些文件也用于一般站点。这意味着当我在管理中时,这些文件应该通过https提供,而当我在一般站点上时,它们应该作为http提供 如何将nginx配置为这种方式 我目前使用的配置如下:nginx通过https和http提供静态文件,http,nginx,configuration,https,static,Http,Nginx,Configuration,Https,Static,所以,我只想保护我的网站的登录和管理部分。问题是管理员使用了一些常用的静态文件,这些文件也用于一般站点。这意味着当我在管理中时,这些文件应该通过https提供,而当我在一般站点上时,它们应该作为http提供 如何将nginx配置为这种方式 我目前使用的配置如下: server { listen 80; server_name site.com www.site.com; root /home/site_folder/web; index index.php;
server {
listen 80;
server_name site.com www.site.com;
root /home/site_folder/web;
index index.php;
location ~ /(get-involved|contribute|api) {
return 301 https://$server_name$request_uri;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param HTTPS on;
fastcgi_param SCRIPT_FILENAME /home/site_folder/web/index.php;
}
location / {
root /home/site_folder/web;
if (-f $request_filename) {
expires max;
break;
}
try_files $uri $uri/index.php;
rewrite ^(.*) /index.php last;
}
}
server {
listen 443 ssl;
ssl_certificate path_to_ssl.crt;
ssl_certificate_key path_to_key.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
server_name site.com www.site.com;
root /home/site_folder/web;
index index.php;
location ~ /(get-involved|contribute|api) {
root /home/site_folder/web;
if (-f $request_filename) {
expires max;
break;
}
try_files $uri $uri/index.php;
rewrite ^(.*) /index.php last;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param HTTPS on;
fastcgi_param SCRIPT_FILENAME /home/site_folder/web/index.php;
}
location / {
return 301 http://$server_name$request_uri;
}
}
不清楚。Nginx不选择如何提供文件。是浏览器选择使用哪种协议(实际上它通常是用html编写的)嘿@AlexeyTen谢谢。我已经添加了我使用的配置。问题是在
/contribute
中的https
下,静态文件(js、css)位于http
下。另外,当我从安全部分返回到非安全部分时,静态文件也没有加载。您已经从https重定向到http。不要对静态文件这样做。静态文件保存在哪里?静态文件在这里:/home/site\u folder/web