https的配置方法
#这个是接口文档的----------------------------------
server {
#侦听80端口
listen 80;
#定义使用 www.nginx.cn访问
server_name tapi.***.net;
rewrite ^(.*) https://$server_name$1 permanent;
}
#微信项目 https配置
server {
listen 443 ssl;
server_name tapi.m***.net;
ssl_certificate /etc/nginx/ssl_key/2147197624dd932.pem;
ssl_certificate_key /etc/nginx/ssl_key/2147197dd410932.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#定义服务器的默认网站根目录位置
root /usr/share/nginx/html/api/public;
#设定本虚拟主机的访问日志
# access_log logs/nginx.access.log main;
#默认请求
location / {
root
/usr/share/nginx/html/api/public;
index
index.html index.htm index.php;
#去除index.php用的
#方法1----
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
#如果文件不存在则尝试TP解析 (方法2)
# try_files $uri /index.php$uri;
}
# 定义错误提示页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# #静态文件,nginx自己处理
# location ~ ^/(images|javascript|js|css|flash|media|static)/ {
# #过期30天,静态文件不怎么更新,过期可以设大一点,
# #如果频繁更新,则可以设置得小一点。
# expires 30d;
# }
#PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
location ~ \.php {
root /usr/share/nginx/html/api/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# set $path_info "";
# set $real_script_name $fastcgi_script_name;
# if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
# set $real_script_name $1;
# set $path_info $2;
# }
# fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
# fastcgi_param SCRIPT_NAME $real_script_name;
# fastcgi_param PATH_INFO $path_info;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
#禁止访问 .htxxx 文件
location ~ /.ht {
deny all;
}
}
普通的80端口配置方法——————————
# #这个是接口文档的----------------------------------
# server {
# #侦听80端口
# listen 80;
# #定义使用 www.nginx.cn访问
# server_name test.m***.net;
# #定义服务器的默认网站根目录位置
# root /usr/share/nginx/html/index/public;
# #设定本虚拟主机的访问日志
# # access_log logs/nginx.access.log main;
# #默认请求
# location / {
# root
# /usr/share/nginx/html/index/public;
# index
# index.html index.htm index.php;
# #去除index.php用的
# #方法1----
# if (!-e $request_filename) {
# rewrite ^(.*)$ /index.php?s=/$1 last;
# break;
# }
# #如果文件不存在则尝试TP解析 (方法2)
# # try_files $uri /index.php$uri;
# }
# # 定义错误提示页面
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# # #静态文件,nginx自己处理
# # location ~ ^/(images|javascript|js|css|flash|media|static)/ {
# # #过期30天,静态文件不怎么更新,过期可以设大一点,
# # #如果频繁更新,则可以设置得小一点。
# # expires 30d;
# # }
# #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
# location ~ \.php {
# root /usr/share/nginx/html/index/public;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
# # set $path_info "";
# # set $real_script_name $fastcgi_script_name;
# # if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
# # set $real_script_name $1;
# # set $path_info $2;
# # }
# # fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
# # fastcgi_param SCRIPT_NAME $real_script_name;
# # fastcgi_param PATH_INFO $path_info;
# fastcgi_split_path_info ^(.+\.php)(/.*)$;
# fastcgi_param PATH_INFO $fastcgi_path_info;
# }
# #禁止访问 .htxxx 文件
# location ~ /.ht {
# deny all;
# }
# }
原文地址:https://www.cnblogs.com/cbywan/p/9128542.html