user root;
#user nobody;
worker_processes 1;
error_log logs/error.log;
#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" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
types_hash_max_size 2048;
#注意这里我们包含了一个proxy.conf文件,该文件也是位于/usr/local/nginx/conf目录,
include proxy.conf;
#下面这堆配置主要用来限制并发连接数,以及压缩内容节省带宽
limit_conn_zone $binary_remote_addr zone=addr:10m;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server {
listen 80;
server_name yaofuqiang.cn www.yaofuqiang.cn;
location /{
return 307 https://www.yaofuqiang.cn;
}
}
server {
listen 80;
server_name game.yaofuqiang.cn;
location /{
return 307 https://game.yaofuqiang.cn;
}
}
server {
listen 80;
server_name blog.yaofuqiang.cn;
location /{
return 307 https://blog.yaofuqiang.cn;
}
}
#监听https协议(默认443端口)
server {
listen 443 ssl;
server_name www.yaofuqiang.cn;
server_tokens off;
charset utf-8;
#限制并发连接数,这里的“addr”是在前面的“ limit_conn_zone”中定义的,名称要保持一致
limit_conn addr 5;
#只允许我们的域名访问
if ($host !~ ^(yaofuqiang.cn|www.yaofuqiang.cn)$ ) {
return 444;
}
#屏蔽非法请求类型
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
#拒绝异常的User-Agents
if ($http_user_agent ~* LWP::Simple|BBBike|wget) {
return 403;
}
if ($http_user_agent ~* Sosospider|YodaoBot) {
return 403;
}
#设置网站根目录
root /usr/local/tomcat/web_index/ROOT;
#设置默认首页
index index.html index.htm index.php;
include /etc/nginx/default.d/*.conf;
#配置ssl证书
ssl_certificate /etc/letsencrypt/live/yaofuqiang.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yaofuqiang.cn/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
#静态请求
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /usr/local/tomcat/web_index/ROOT;
expires 30d;
}
#admin目录转交Tomcat处理
location ~ /admin/ {
proxy_pass http://139.199.211.49:8080;
}
#动态请求
location ~ \.(do|jsp|action|jspx|shtml)$ {
proxy_pass http://139.199.211.49:8080;
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;
client_max_body_size 10m; #允许客户端请求的最大单文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数
proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间
proxy_read_timeout 90; #连接成功后,后端服务器响应时间
proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 6 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
#phpMyAdmin目录转交php处理
location ~ /phpMyAdmin/ {
fastcgi_index index.php;
location ~ .*\.(php|php5)?$ {
#这里的9000端口是在/etc/php.ini中配置的,9000是默认值,你也可以修改
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#/配置auth_basic验证
auth_basic "security";
#密码保存在哪里
auth_basic_user_file /usr/local/nginx/conf/passwd;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 443 ssl;
server_name game.yaofuqiang.cn;
server_tokens off;
charset utf-8;
#限制并发连接数,这里的“addr”是在前面的“ limit_conn_zone”中定义的,名称要保持一致
limit_conn addr 5;
#只允许我们的域名访问
if ($host !~ ^(game.yaofuqiang.cn)$ ) {
return 444;
}
#屏蔽非法请求类型
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
#拒绝异常的User-Agents
if ($http_user_agent ~* LWP::Simple|BBBike|wget) {
return 403;
}
if ($http_user_agent ~* Sosospider|YodaoBot) {
return 403;
}
#设置网站根目录
root /usr/local/tomcat/web_game/ROOT;
#设置默认首页
index index.html index.htm index.php;
include /etc/nginx/default.d/*.conf;
#配置ssl证书
ssl_certificate /etc/letsencrypt/live/game.yaofuqiang.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/game.yaofuqiang.cn/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
#静态请求
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /usr/local/tomcat/web_game/ROOT;
expires 30d;
}
#admin目录转交Tomcat处理
location ~ /admin/ {
proxy_pass http://139.199.211.49:8081;
}
#动态请求
location ~ \.(do|jsp|action|jspx|shtml)$ {
proxy_pass http://139.199.211.49:8081;
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;
client_max_body_size 10m; #允许客户端请求的最大单文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数
proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间
proxy_read_timeout 90; #连接成功后,后端服务器响应时间
proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 6 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
#phpMyAdmin目录转交php处理
location ~ /phpMyAdmin/ {
fastcgi_index index.php;
location ~ .*\.(php|php5)?$ {
#这里的9000端口是在/etc/php.ini中配置的,9000是默认值,你也可以修改
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#/配置auth_basic验证
auth_basic "security";
#密码保存在哪里
auth_basic_user_file /usr/local/nginx/conf/passwd;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 443 ssl;
server_name blog.yaofuqiang.cn;
server_tokens off;
charset utf-8;
#限制并发连接数,这里的“addr”是在前面的“ limit_conn_zone”中定义的,名称要保持一致
limit_conn addr 5;
#只允许我们的域名访问
if ($host !~ ^(blog.yaofuqiang.cn)$ ) {
return 444;
}
#屏蔽非法请求类型
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
#拒绝异常的User-Agents
if ($http_user_agent ~* LWP::Simple|BBBike|wget) {
return 403;
}
if ($http_user_agent ~* Sosospider|YodaoBot) {
return 403;
}
#设置网站根目录
root /usr/local/tomcat/web_blog/ROOT;
#设置默认首页
index index.html index.htm index.php;
include /etc/nginx/default.d/*.conf;
#配置ssl证书
ssl_certificate /etc/letsencrypt/live/blog.yaofuqiang.cn/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/blog.yaofuqiang.cn/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
#静态请求
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /usr/local/tomcat/web_blog/ROOT;
expires 30d;
}
#admin目录转交Tomcat处理
location ~ /admin/ {
proxy_pass http://139.199.211.49:8082;
}
#动态请求
location ~ \.(do|jsp|action|jspx|shtml)$ {
proxy_pass http://139.199.211.49:8082;
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;
client_max_body_size 10m; #允许客户端请求的最大单文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数
proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间
proxy_read_timeout 90; #连接成功后,后端服务器响应时间
proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 6 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
#phpMyAdmin目录转交php处理
location ~ /phpMyAdmin/ {
fastcgi_index index.php;
location ~ .*\.(php|php5)?$ {
#这里的9000端口是在/etc/php.ini中配置的,9000是默认值,你也可以修改
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#/配置auth_basic验证
auth_basic "security";
#密码保存在哪里
auth_basic_user_file /usr/local/nginx/conf/passwd;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}