因为内网服务越来越多,各种IP加端口地址根本记不住,于是用Nginx做反响代理,也可以很好管理内网的地址分发。
下面提供几种Nginx配置模板。因为也是自己摸索着配置的,有错误的地方请指正,谢谢先。
# 重载配置
nginx -s reload
# php配置
server {
listen 88;
server_name _;
location ^~ /myphp{
alias /www/myphp;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^/myphp/(.*)$ /index.php/$1 last;
}
location ~ \.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
}
# 反向代理1
# 需要传http header参数的
location ~ ^/api/(.*)$ {
proxy_pass http://127.0.0.1:8080/$1;
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;
}
#反向代理2
# 请求/xxx/a.html,指向的是http://localhost:82/a.html
location /xxx {
proxy_pass http://localhost:82/;
index index.html index.htm index.jsp;
}
#反向代理3
# 请求/xxx/a.html,指向的是http://localhost:82/xxx/a.html
location /xxx {
proxy_pass http://localhost:82;
index index.html index.htm index.jsp;
}
#静态web server1
#请求/wiki/xxx.html,指向的是/data/work/gitbook/_book/xxx.html
location /wiki {
alias /data/work/gitbook/_book/;
index index.html index.htm index.jsp;
}
#静态web server2
#请求/wiki/xxx.html,指向的是/data/work/gitbook/_book/wiki/xxx.html
location /wiki {
root /data/work/gitbook/_book/;
index index.html index.htm index.jsp;
}
#Nginx搭建文件下载服务器
server {
listen 8090;
server_name _;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
alias /data/work/www/download;
}
charset utf-8;
}
来源:oschina
链接:https://my.oschina.net/u/4395893/blog/3318187