版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012599988/article/details/81561219
comm.inc.conf :
server_tokens off;
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 75s;
cors.inc.conf:
if ($http_origin) {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' true;
}
if ($request_method = OPTIONS) {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' true;
add_header 'Access-Control-Max-Age' 864000;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS, PATCH';
add_header 'Access-Control-Allow-Headers' *,authorization;
add_header 'Content-Length' 0;
add_header 'Content-Type' 'text/plain, charset=utf-8';
return 204;
}
favicon.inc.conf :
favicon.ico
文件是浏览器收藏网址时显示的图标,当第一次访问页面时,浏览器会自动发起请求获取页面的favicon.ico文件。当/favicon.ico文件不存在时,服务器会记录404日志。
location = /favicon.ico {
expires max;
empty_gif; #配置empty_gif来给请求返回一个1x1,大小为43字节的空白图片来解决
log_not_found off; #关闭日志
access_log off; #不记录在access.log
}
gzip.inc.conf :
gzip on;
gzip_comp_level 3;
gzip_min_length 800;
gzip_proxied any;
gzip_buffers 64 8k;
gzip_http_version 1.0;
gzip_vary on;
gzip_types text/plain text/css text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss image/svg+xml;
log_format.inc.conf :
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format f_nginx_2 "\n$remote_addr => $host:$server_port '$request' [$status] ($bytes_sent)Bytes \n$http_user_agent\nUp-Cookies:$http_cookie \nDown-Cookies: $sent_http_set_cookie";
log_format f_nginx_3 '$remote_addr => $scheme://$host:$server_port [$status] ($http2)\n'
'$request (Byte: $body_bytes_sent ratio: $gzip_ratio) time_elapsed: $request_time\n'
'Accept-Encoding: $http_accept_encoding | Content-Type: $sent_http_content_type\n'
'User-Agent: $http_user_agent\n';
no_img.inc.conf :
location ~* \.(jpg|jpeg|webp|gif|png|css|js|swf)$ {
return 444;
}
proxy.inc.conf :
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_hide_header X-Powered-By;
#proxy_hide_header ETag;
#proxy_hide_header Last-Modified;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Accept-Encoding "";
proxy_buffering on;
proxy_buffers 100 8K;
proxy_redirect ~*^http://[^/]+(.+)$ https://$host$1;
proxy_intercept_errors off;
proxy_connect_timeout 5s;
psg.inc.conf :
passenger_max_requests 5000;
passenger_core_file_descriptor_ulimit 32000;
passenger_show_version_in_header off;
passenger_friendly_error_pages off;
passenger_abort_on_startup_error on;
passenger_ignore_client_abort on;
passenger_max_pool_size 10;
passenger_pool_idle_time 600;
#passenger_log_file /js/logs/psg.err.log;
passenger_log_level 3;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 48h;
ssl_stapling on;
#ssl_stapling_verify on;
resolver 223.5.5.5 223.6.6.6 valid=600s;
resolver_timeout 10s;
使用例:
server {
server_name nst.un.com;
listen 80;
listen 443 ssl http2;
passenger_enabled off;
index index.html;
include nginx.inc.d/favicon.inc.conf;
#include nginx.inc.d/no_img.inc.conf;
location / {
include nginx.inc.d/cors.inc.conf;
proxy_pass http://localhost:8001;
}
}
----------
server {
server_name dev.un.com;
listen 80;
listen 443 ssl http2;
root /mby/h5_sites/dev/public;
index index.html;
include nginx.inc.d/favicon.inc.conf;
#include nginx.inc.d/no_img.inc.conf;
location / {
include nginx.inc.d/cors.inc.conf;
try_files $uri $uri/ /index.html;
}
}
----------
server {
server_name ev.un.com;
listen 80;
listen 443 ssl http2;
root /mby/h5_sites/live_web;
index index.html;
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
}