worker_processes auto;
//错误日志目录
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
//最大连接数
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;//访问日志地址
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server; //端口
listen [::]:80 default_server;//监听端口
server_name zyp.com;//域名
# root /usr/share/nginx/html;
//指定状态码页面
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
//https专用端口
listen 443 ssl;
server_name open.zyp.com;
root /usr/local/nginx/html;
//配置证书
ssl_certificate /usr/nginx/nginx-1.12.0/cert/capa/214789665020410.pem;
ssl_certificate_key /usr/nginx/nginx-1.12.0/cert/capa/214789665020410.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
//加入跨域请求头,方便前端和后端联调,
location / {
add_header Access-Control-Allow-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 ^~ /yh/ {
proxy_pass http://127.0.0.1:8080/yh/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}