Nginx——安装与虚拟主机配置(域名非80端口问题)
一、引言
因为甲方提出问题:一个服务器与IP,两个域名a、b分别对应两个要部署的网站,这个一般是一个域名a对应一个主机服务器ip的默认80端口,另外的网站只能用其他端口(如b:8080对应主机ip:8080)。
由于这个原因,所以有了这篇博文,使用了nginx反向代理解决这个问题,核心思想是nginx服务器占用80端口,我们访问nginx,nginx利用反向代理转到最终部署的非80端口网站。
二、Nginx安装
1、下载nginx
链接为点击打开链接,下载windows版本
2、安装配置
直接解压到相应的位置
然后在cmd进入nginx主目录进行操作
打开软件 start nginx
停止软件 nginx -s stop
重新加载配置文件 nginx -s reload
强行杀进程 taskkill /F /IM nginx.exe > nul
如果你安装好了的话,默认打开localhost(前提你没有占80端口),就能看到nginx页面了,证明配置好了
三、虚拟主机配置
1、重要配置文件
在conf中找到下面的文件
2、进行配置
下面是我配置的两个server,server1中默认的是80端口,地址www.a.com,映射到localhost上面的网站;server2中默认的是80端口,地址www.b.com,映射到某个外网的网站。有下面的例子够用了,不过具体该文件的配置说明查看点击打开链接
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;#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 logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name http://www.a.com;#charset koi8-r;#access_log logs/host.access.log main;location / {#root html;#index index.html index.htm;proxy_set_header Host $host;proxy_set_header X-Real-Ip $remote_addr;proxy_set_header X-Forwarded-For $remote_addr;proxy_pass http://localhost:90/jgs/index_login.html;} #error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}server {listen 80;server_name http://www.b.com;#charset koi8-r;#access_log logs/host.access.log main;location / {#root html;#index index.html index.htm;proxy_set_header Host $host;proxy_set_header X-Real-Ip $remote_addr;proxy_set_header X-Forwarded-For $remote_addr;proxy_pass http://123.56.23.171:8080;} #error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}
四、总结
- 一个服务器ip部署多个不同域名网站,不带端口;
- nginx安装;
- nginx配置虚拟主机;
Nginx——安装与虚拟主机配置(域名非80端口问题)相关推荐
- Nginx安装与虚拟主机配置shell脚本
今天继续给大家介绍Linux运维相关知识,本文主要内容是Nginx安装与虚拟主机配置shell脚本. 一.NGINX安装 在今天的脚本上,我们开始尝试使用函数和参数,以增强脚本的灵活性和实现脚本的模块 ...
- 一键去除域名非80端口,去掉域名后面带的端口号快速解决方案
一键去除域名非80端口,去掉域名后面带的端口号快速解决方案 参考文章: (1)一键去除域名非80端口,去掉域名后面带的端口号快速解决方案 (2)https://www.cnblogs.com/phpw ...
- 12.6-12.9 Nginx安装,默认虚拟主机,用户认证,域名重定向
12.6 Nginx安装 大纲 1 进入src目录,把nginx下载在此目录 #cd /usr/local/src #wget http://nginx.org/download/nginx-1.8 ...
- Nginx编译安装与虚拟主机配置
1.Nginx的简介 nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器:因它的稳定性.丰富的功能集.示例配置文件和低系统资源的消耗而闻名,nginx还有非 ...
- Nginx实现多虚拟主机配置
一.Nginx的应用概述 Nginx作为一款高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.主要有以下3方面的应用: 1.http服务器 Nginx是一个http服 ...
- 在window 10 x64下Apache24的下载、安装及虚拟主机配置(以wordpress为例)
什么是Apache 关于Apache是什么及与tomcat的区别联系见上一篇文章,这里我们只讲window下的Apache web服务器的安装及虚拟主机的配置. Apache下载 (1)打开百度,搜索 ...
- 基于不同IP地址下的虚拟主机配置以及基于不同端口下的虚拟主机配置
基于不同IP地址下的虚拟主机配置 一.配置vhost.conf(主配置文件) (一).进入主配置文件目录:cd /etc/httpd/conf.d (二).配置主配置文件:vim vhost/conf ...
- 11-4 12 Nginx安装 默认虚拟主机 用户认证 域名重定向
2019独角兽企业重金招聘Python工程师标准>>> 12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx域名重定向 扩展 ngin ...
- Apache源码安装和虚拟主机配置
源码安装Apache 1.上传Apache源码安装所需软件包 2.安装: 安装顺序 apr->apr-util->pcre->httpd 安装编译环境 yum -y install ...
最新文章
- es6 generator_让我们探索一下ES6 Generators
- 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame
- Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8
- java面试题在线做_java考试题目及答案也可以当面试题
- Android开发:什么是IBinder
- RedHat Enterprise Linux 6.4使用Centos 6的yum源问题
- 图像抠图Image Matting算法调研
- 应用的大数据:医疗保健的经济学
- 12GB超大内存!华为超级旗舰手机悄悄现身
- 【clickhouse】Application: DB::Exception: Duplicate interserver IO endpoint: DataPartsExchange
- Ubuntu18.04取消VIM自动备份文件
- 毕设题目:Matlab智能算法VRP(车辆路径规划)
- 用PHP抓取淘宝商品的用户晒单评论+图片实例
- python计算棋盘放米的故事_在棋盘上64个格子里放大米粒的故事
- 简易计算器app的制作
- 用Qt实现QQ好友列表界面伸缩功能(完全一模一样)(伸展和收缩、抽屉效果、类似树形控件)(鼠标划过QSS效果)
- 汇编语言程序设计51单片机
- iOS开发--AVPlayer实现音乐播放器
- C语言函数之 fabs()
- 关于MDL的一些事(2)
热门文章
- AWT_事件监听2(Java)
- 爬取猫眼电影相关信息
- 一般试卷的纸张大小是多少_档案产品库纸张整理专家
- C# 禁止用户关掉对话框的方法
- Halcon OCR识别
- componentDidUpdate vs componentWillReceiveProps
- linux gulp安装教程,Linux环境NodeJS安装及Gulp安装
- 【汇编语言与计算机系统结构笔记07】条件码,比较、测试、条件跳转与条件转移指令,结合微体系结构与流水的说明
- 更名OpenShift容器平台,红帽实现战略性转变
- python requests库详解_python爬虫之路(一)-----requests库详解