在实际工作中,我们总是会用到nginx做为反向代理及统一出口内容的配置,这里我们记录下在实际项目中进行配置引用配置文件到初始配置文件中的实例。
基础配置文件内容nginx.conf
worker_processes auto;
events {
use epoll;
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_host|"$http_referer"|'
'"$http_user_agent"|$http_x_forwarded_for|$upstream_cache_status|'
'"$upstream_http_content_type"|$request_time|$upstream_response_time|$bytes_sent|$request_length|'
'"$upstream_addr"';
access_log /skyfans/logs/nginx/access.log main;
error_log /skyfans/logs/nginx/error.log notice;
sendfile on;
keepalive_timeout 65;
#注意引用文件的获取位置路径,若你的配置文件路径不放在此处,请修改为你的路径
include conf.d/*.conf;
}
引用文件配置内容文件,这里仅举例一个配置项,大家仅做参考即可。
upstream.conf, 文件安装路径位置:/etc/nginx/conf.d(注意你实际安装的nginx的配置路径,不一定和我的一样)
#注意修改为你的项目所代理的内容
upstream plugin.com {
ip_hash;
#注意修改你的项目的IP地址及端口
server 172.1.1.200:8080;
server 172.1.1.201:8080;
}
server {
#注意修改为你的实际端口
listen 8080;
server_name plugin;
#charset koi8-r;
charset utf-8;
#access_log logs/host.access.log main;
location / {
#注意修改成你项目的配置
proxy_pass http://plugin.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#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;
}
}