主域名多端口访问
在dns nameserver设置a记录
将 指向服务器ip
开放所需端口,修改nginx配置文件
比如我们有两个服务分别开放在80端口和8080端口
如果有iptable,先开放端口:
iptables -a input -ptcp --dport 80 -j accept iptables -a input -ptcp --dport 8080 -j accept
修改配置文件:
#path: /usr/local/nginx/conf/nginx.conf server { listen 80; server_name www.xxx.com; access_log /data/www/log/33.33.33.33_nginx.log combined; index index.html index.htm index.php; include /usr/local/nginx/conf/rewrite/none.conf; root /data/www/website/33.33.33.33:80; location ~ [^/]\.php(/|$) { fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; access_log off; } location ~ .*\.(js|css)?$ { expires 7d; access_log off; } } server { listen 8080; server_name a.xxx.com; access_log /data/www/log/33.33.33.33:8080_nginx.log combined; index index.html index.htm index.php; include /usr/local/nginx/conf/rewrite/none.conf; root /data/www/website/33.33.33.33:8080; location ~ [^/]\.php(/|$) { fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; access_log off; } location ~ .*\.(js|css)?$ { expires 7d; access_log off; } }
关键就是两个 server 段配置,你也可以把这两段拆成两个配置文件,放到
/etc/nginx/conf.d/
目录下面;
子域名多端口访问
这种访问比较傻,因为你的8080端口的访问需要 http://xxx.com:8080 这样的格式;
而且如果有两个不同的cgi,比如80端口对应一个php web服务, 8080端口对应一个nodejs web服务;而我们的nodejs自带web服务,已经在8080端口监听了,这怎么办?
这个时候我们需要nginx的反向代理功能,并在dns server上面增加一条a记录,最终实现
www.xxx.com 访问80端口
a.xxx.com 通过nginx转发访问8080端口服务
增加一条a记录
将 a.xxx.com 指向服务器ip
nginx配置模板如下:
#path: /usr/local/nginx/conf/nginx.conf server { listen 80; server_name www.xxx.com; access_log /data/www/log/33.33.33.33_nginx.log combined; index index.html index.htm index.php; include /usr/local/nginx/conf/rewrite/none.conf; root /data/www/website/33.33.33.33:80; location ~ [^/]\.php(/|$) { fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ { expires 30d; access_log off; } location ~ .*\.(js|css)?$ { expires 7d; access_log off; } } server { listen 80; listen [::]:80; server_name a.xxx.com; proxy_connect_timeout 300s; proxy_send_timeout 300s; proxy_read_timeout 300s; fastcgi_send_timeout 300s; fastcgi_read_timeout 300s; location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header upgrade $http_upgrade; proxy_set_header connection 'upgrade'; proxy_set_header host $host; proxy_cache_bypass $http_upgrade; try_files $uri $uri/ =404; } }
nginx重新载入配置文件
nginx -s reload
以上是Nginx如何配置多端口多域名访问的详细内容。更多信息请关注PHP中文网其他相关文章!

NGINX可用于提升网站性能、安全性和可扩展性。1)作为反向代理和负载均衡器,NGINX可优化后端服务和分担流量。2)通过事件驱动和异步架构,NGINX高效处理高并发连接。3)配置文件允许灵活定义规则,如静态文件服务和负载均衡。4)优化建议包括启用Gzip压缩、使用缓存和调整worker进程。

NGINXUnit支持多种编程语言,通过模块化设计实现。1.加载语言模块:根据配置文件加载相应模块。2.应用启动:调用语言运行时执行应用代码。3.请求处理:将请求转发给应用实例。4.响应返回:将处理后的响应返回给客户端。

NGINX和Apache各有优劣,适合不同场景。1.NGINX适合高并发和低资源消耗场景。2.Apache适合需要复杂配置和丰富模块的场景。通过比较它们的核心特性、性能差异和最佳实践,可以帮助你选择最适合需求的服务器软件。

确认 Nginx 是否启动的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 检查端口 80 是否开放;3. 查看系统日志中 Nginx 启动消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

要关闭 Nginx 服务,请按以下步骤操作:确定安装类型:Red Hat/CentOS(systemctl status nginx)或 Debian/Ubuntu(service nginx status)停止服务:Red Hat/CentOS(systemctl stop nginx)或 Debian/Ubuntu(service nginx stop)禁用自动启动(可选):Red Hat/CentOS(systemctl disable nginx)或 Debian/Ubuntu(syst

如何在 Windows 中配置 Nginx?安装 Nginx 并创建虚拟主机配置。修改主配置文件并包含虚拟主机配置。启动或重新加载 Nginx。测试配置并查看网站。选择性启用 SSL 并配置 SSL 证书。选择性设置防火墙允许 80 和 443 端口流量。

服务器无权访问所请求的资源,导致 nginx 403 错误。解决方法包括:检查文件权限。检查 .htaccess 配置。检查 nginx 配置。配置 SELinux 权限。检查防火墙规则。排除其他原因,如浏览器问题、服务器故障或其他可能的错误。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

禅工作室 13.0.1
功能强大的PHP集成开发环境

WebStorm Mac版
好用的JavaScript开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)