配置文件如下:
# http
server {
listen 80;
server_name test.th5.gezlife.com;
# 根目录
root /Data/home/test/release/environments/dev/backend/web;
index index.php;
# 日志
access_log /Data/logs/nginx/test.th5.gezlife.com-access.log;
error_log /Data/logs/nginx/test.th5.gezlife.com-error.log;
# 设置目录浏览
# autoindex on;
# autoindex_exact_size off;
# autoindex_localtime on;
location / {
try_files $uri @rewrite;
}
location @rewrite {
set $static 0;
if ($uri ~ \.(html|css|js|txt|jpg|jpeg|png|gif|bmp|ico|woff|eot|svg|css\.map|min\.map)$) {
set $static 1;
}
if ($static = 0) {
rewrite ^(.*)$ /index.php?s=$1 last;
}
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_read_timeout 150;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# https
server {
listen 443;
servername test.gezlife.com;
root /Data/code/apis;
# 日志
access_log /Data/logs/nginx/test.th5.gezlife.com-access.log;
error_log /Data/logs/nginx/test.th5.gezlife.com-error.log;
ssl on;
# 证书
ssl_certificate keys/njlj.net.pem;
ssl_certificate_key keys/njlj.net.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
## 跨域请求配置
#add_header 'Access-Control-Allow-Credentials' 'true';
#add_header 'Access-Control-Allow-Origin' $http_origin;
#add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_read_timeout 150;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}