nginx配置ssl,http80端口跳转ssl443端口并保留http的url参数
nginx
server {
listen 80;
server_name 您的域名;
location / {
# 301 跳转到https带上url参数$request_uri;
return 301 https://$server_name$request_uri;
}
}
server {
# 监听80端口
listen 443;
# 绑定域名
server_name 您的域名;
# 编码
charset utf-8;
# 网站根目录
root /web_path;
# 主机默认文档
index index.html index.php;
# 成功与错误日志
# access_log /usr/local/nginx/logs/自定义名称.access.log;
# error_log /usr/local/nginx/logs/自定义名称.error.log;
# # 开启ssl
# ssl on;
# # ssl证书存放路径
# ssl_certificate /ssl_path/证书.crt;
# # ssl证书存放路径
# ssl_certificate_key /ssl_path/证书.key;
# ssl_session_timeout 5m;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# # 按照这个协议配置
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
# # 按照这个配置
# ssl_prefer_server_ciphers on;
# URL重写(根据实际需求填写)
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
try_files $uri $uri/ /index.php?$args;
}
# nginx 和 php 关联
# 配置FastCGI,PHP 脚本请求全部转发到 FastCGI处理
location ~ .*\.php$ {
# 设置监听端口(多版本php用端口号区分
fastcgi_pass 127.0.0.1:9000;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
}
# 以下配置在生产环境切勿打开,用于本地环境查看网站目录
# default_type application/octet-stream;
# autoindex on;
# autoindex_exact_size off;
# autoindex_localtime on;
}