Nginx一般配置
文件为 nginx.conf ,一般配置内容如下:
user root;
worker_processes auto;
#pid /var/run/nginx.pid;
#error_log /dev/stderr;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" "$http_host" '
'$status $body_bytes_sent "$http_referer" "$http_upgrade" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
# tcp_nopush on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
client_max_body_size 100M;
client_body_buffer_size 500M;
proxy_read_timeout 90;
#PC网关
upstream pcgateway {
server 127.1.1.10:8087;
server 127.1.1.11:8087;
}
#APP网关
upstream appgateway {
server 127.1.1.10:8089;
server 127.1.1.11:8089;
}
#http 自动转向到https
server {
listen 80;
server_name www.myweb.com;
rewrite ^(.*) https://$server_name$1 permanent;
}
server {
listen 443 ssl;
server_name www.myweb.com;
# server_name 127.0.0.1;
ssl_certificate ssl-cert/server_new.crt;
ssl_certificate_key ssl-cert/server_new.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
rewrite_log on;
if ($time_iso8601 ~ '(\d{4}-\d{2}-\d{2})') {
set $tttt $1;
}
access_log /var/logs/app443/website-$tttt.log main;
error_log /var/logs/app443/error.log error;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
location /pcApi/{
proxy_redirect off;
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_pass http://pcgateway/;
}
location /appApi/ {
proxy_redirect off;
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_pass http://appgateway/;
}
location /{
index index.html index.htm;
root /usr/local/website;
}
}
}