[Nginx]单机环境的多应用配置
2024-10-18 13:41:41
# 服务层
# https://github.com/farwish/alconservice
# alconservice.conf
server {
listen 8090;
root /home/www/alconService/public; location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?_url=$uri&$args;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} location /favicon.ico {
log_not_found off;
access_log off;
} access_log logs/alconservice.access.log;
}
# 前端应用
# front.yk.conf
server {
listen 80;
server_name front.kkys.com; root /home/www/web; location / {
index index.html index.htm index.php;
} location /api/ {
proxy_pass http://dev.kkys.com/yk/;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; #fastcgi_param PATH_INFO $fastcgi_path_info;
#fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
# 社区接口
# yk.up
server {
listen 81;
root /home/www/Yk/public; location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?_url=$uri&$args;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} location /favicon.ico {
log_not_found off;
access_log off;
} access_log logs/yk.access.log;
}
# 检索接口
# https://github.com/farwish/alconseek
# speed.up
server {
listen ;
root /home/www/speed/public; location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?_url=$uri&$args;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} location /favicon.ico {
log_not_found off;
access_log off;
} access_log logs/speed.access.log;
}
# 百科接口
# baike.up
server {
listen ;
root /home/www/baike/public; location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?_url=$uri&$args;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} location /favicon.ico {
log_not_found off;
access_log off;
} access_log logs/baike.access.log;
}
# 后端接口总代理
# proxy-all.conf
# 注意路径: 当前文件由nginx.conf引用
include vhost/*.up; upstream yk-backend {
server 127.0.0.1:81;
}
upstream speed-backend {
server 127.0.0.1:82;
}
upstream baike-backend {
server 127.0.0.1:83;
} server {
listen 80;
server_name dev.kkys.com; location / {
root /home/www;
index index.html index.htm index.php;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # 结尾不加/,访问记录是 //frontend/index/detail/1212
# 加了/,访问记录是 /frontend/index/detail/1212
location /yk/ {
proxy_pass http://yk-backend/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
}
location /speed/ {
proxy_pass http://speed-backend/;
}
location /baike/ {
proxy_pass http://baike-backend/;
}
}
# 用户中心
# ucenter.conf
server {
listen 8092;
root /home/www/ucenter-front; location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
} server {
listen 8093;
root /home/www/ucenter/public; location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?_url=$uri&$args;
} location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
} upstream ucenter-front {
server 127.0.0.1:8092;
} upstream ucenter {
server 127.0.0.1:8093;
} server {
listen 80;
server_name ucenter.com; location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?_url=$uri&$args;
} location /favicon.ico {
log_not_found off;
access_log off;
} location /pcenter/ {
proxy_pass http://ucenter-front/;
} location /ucenter/ {
proxy_pass http://ucenter/;
}
}
以上 location 的配置是针对 phalcon 框架而言,下面是针对 symfony 应用的。
symfony.conf
server {
listen 80;
server_name symfony.com;
root /home/www/symfony/web; location / {
index index.html index.htm index.php;
try_files $uri /app.php$is_args$args;
} # DEV
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # symfony.com/app.php/some-path
# Remove the internal directive to allow URIs like this.
#internal;
} access_log logs/symfony.access.log;
}
小结:
多应用基于项目拆分的场景或思想,独立开发、独立部署,可以做到互不影响,如同前后端分离一样。
这里大家会发现,反向代理不仅可以简化多应用的部署,还能做到负载均衡,只需增加 upstream机器 就能横向扩展。
其实也完全可以 以大模块的方式整合成一个强大应用,从易维护上来讲更容易一点。两种方式都各有优势。
Link:http://www.cnblogs.com/farwish/p/6128712.html
最新文章
- 【leedcode】 Median of Two Sorted Arrays
- 【转】el表达式的判断符
- 【原创】使用Fiddler抓取手机网络包
- nginx ssl证书安装配置
- MVC小系列(一)【制作表格】
- U盘装系统出现错误 安装失败怎么办
- kendo ui grid 汉化
- 管道实现进程间通讯 、WaitNamedPipe
- leetcode[71] Sqrt(x)
- iOS网络编程笔记——编写自己的网络客户端
- 流处理与消息队列------《Designing Data-Intensive Applications》读书笔记16
- 基于Orangpi Zero和Linux ALSA实现WIFI无线音箱(三)
- 我曾做过陈士成,也做过孔乙己,还做过阿Q
- 阅读github上的项目源码
- TreeGrid 控件集 :delphi 学习群 ---- 166637277 (Delphi学习交流与分享)
- Java SimpleDateFormat 中英文时间格式化转换
- python学习之----爬取图片
- KrakenD: API Gateway and Manager
- day16(jdbc进阶,jdbc之dbUtils)
- 类的专有方法(__getitem__和__setitem__)
热门文章
- Zabbix实战-简易教程--技巧(本地化)
- 【算法】赫夫曼树(Huffman)的构建和应用(编码、译码)
- flask设置配置文件的四钟方式
- bzoj 1084;vijos 1191 [SCOI2005] 最大子矩阵
- 洛谷 P1972 [SDOI2009]HH的项链【莫队算法学习】
- SecureCRT连接虚拟机中的Linux系统(Ubuntu)_Linux教程
- 【C#】数据库脚本生成工具(二)
- [国嵌攻略][070][GDB调试程序]
- UVA 673 Parentheses Balance (栈)
- setTimeout,setInterval运行原理