nginx.conf
#user nginx;
worker_processes auto;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#error_log logs/error.log debug;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main escape=none '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
include /usr/local/nginx/conf/vhost/*.conf;
}
配置多域名
注意 nginx.conf文件的最下面一行配置进行加载每个独立域名的配置信息
include /usr/local/nginx/conf/vhost/*.conf;
app.com
本地配置hosts文件后
vhost目录下创建一个app.conf文件
server {
listen 80;
server_name ~^(www\.)?baidu.com;
rewrite ^(.*)$ https://${server_name}$1 permanent;
}
server {
listen 443 ssl; #监听端口
server_name ~^(www\.)?baidu.com;
charset UTF-8;
ssl_certificate /usr/local/nginx/key/baidu/4919621_www.baidu.com.pem; #证书位置
ssl_certificate_key /usr/local/nginx/key/baidu/4919621_www.baidu.com.key; #私钥位置
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5; #密码加密方式
ssl_prefer_server_ciphers on; # ssl_prefer_server_ciphers on; #
access_log logs/baidu.access.log main;
lua_code_cache off;
location /api {
# 调用lua脚本处理参数url encode转义操作
set_by_lua_file $modify_args '/usr/local/nginx/script/lua/encode_args.lua';
proxy_redirect off;
proxy_pass http://127.0.0.1:8081$uri?$modify_args;
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
}
location / {
root html/baidu/https;
index index.html index.htm;
}
}