在大部分情况下,不管域名绑定也好,第三方公众号或小程序都会要求只能使用80端口。
只准使用80端口有几个意思
一、80端口是不需要显性添加的。
二、80端口比较安全,就怕用户使用21(FTP)、22(ssh远程访问端口)3389(win远程访问端口)
那么怎么一个服务器绑定多个域名或公众号绑定多个服务呢?nginx和iis都可以实现。以下是通过nginx配置。
http://nginx.org/en/download.html
解压以后得到这个目录
打开 conf\nginx.conf
server { listen 80; #使用的端口 server_name localhost; #域名 location / { #后缀 root html; index index.html index.htm; #默认访问页面 } }
最主要的是以上内容,其他都不重要
进入正题
一、使用80端口绑定不同的域名
server { listen 80; server_name www.baidu.com; location / { #配置本地html页面 root D:/abc; index index.html index.htm; } } server { listen 80; server_name www.wy.com; location / { #配置本地服务 proxy_pass http://127.0.0.1:8080/; } }
二、通过不同的后缀配置不同服务
server { listen 80; server_name www.baidu.com; #charset koi8-r; #access_log logs/host.access.log main; root D:/abc; index index.html index.htm; location /xtimg/ { proxy_pass http://127.0.0.1:8010/; } #location /sc/ { # proxy_pass http://127.0.0.1:8089/; #} location /xysp/ { proxy_pass http://127.0.0.1:8011/; } }
www.baidu.com/xtimg == http://127.0.0.1:8010
www.baidu.com/sc == http://127.0.0.1:8089
www.baidu.com/xysp == http://127.0.0.1:8011
通过以上方式只要服务器性能足够,想绑定多少个服务就多少个了。
以下是配置静态图片的配置
server { listen 8010; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { alias d:/xzcimg/; autoindex on; } location /upload/ { alias d:/xzcimg/; autoindex on; } location ~ .*\.(gif|jpg|jpeg|png)$ { expires 24h; root d:/xzcimg/;#指定图片存放路径 proxy_temp_path d:/xzcimg/;#图片访问路径 } }
www.baidu.com:8010/*.jpg 直接访问d:/xzcimg/下的图片
如果不想使用8010端口也可以使用上面的配置配置成80端口
- 海报