使用Nginx配置来动态解析Nginx/Html目录下文件夹做为二级域名的前缀
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用Nginx配置来动态解析Nginx/Html目录下文件夹做为二级域名的前缀,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1692字,纯文字阅读大概需要3分钟。
内容图文
![使用Nginx配置来动态解析Nginx/Html目录下文件夹做为二级域名的前缀](/upload/InfoBanner/zyjiaocheng/933/9cf4699b6eb147fb89f5600d7bbd6f14.jpg)
同一台服务器可能需要部署多个程序,这里使用nginx解析php程序,反向代理tomcat java程序。可以实现动态解析域名,经过Nginx配置来动态解析Nginx/Html目录下的文件夹,做为二级域名。
准备工作:需要提前装好nginx,部署好程序,程序放在nginx/html目录下。
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
include /etc/nginx/conf.d/*.conf
1.动态解析,将根目录下的文件夹动态自动解析成二级域名
server {
listen 80;
server_name ~^(?<subdomain>.+).richwit.cn$ www.richwit.cn;
index index.html index.htm index.php;
root /usr/share/nginx/html/$subdomain/;
location ~ .php$ {
#fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME documentrootdocumentrootfastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 7d;
}
}
2.Java程序 tomcat部署,nginx反向代理
server {
listen 80;
server_name o2o.richwit.cn;
location / {
proxy_pass http://localhost:8088;
root o2o;
index index.html index.htm index.php;
}
}
根据解析的域名即可同时运行多个程序
内容总结
以上是互联网集市为您收集整理的使用Nginx配置来动态解析Nginx/Html目录下文件夹做为二级域名的前缀全部内容,希望文章能够帮你解决使用Nginx配置来动态解析Nginx/Html目录下文件夹做为二级域名的前缀所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。