濮阳杆衣贸易有限公司

主頁 > 知識(shí)庫 > nginx配置二級(jí)域名的示例代碼

nginx配置二級(jí)域名的示例代碼

熱門標(biāo)簽:如何分析地圖標(biāo)注 高德地圖標(biāo)注好做嗎 新余高德地圖標(biāo)注怎么修改 撫順地圖標(biāo)注 外呼系統(tǒng)坐席費(fèi)計(jì)入會(huì)計(jì)哪個(gè)科目 大連400電話如何申請(qǐng) 電銷機(jī)器人價(jià)值 電銷機(jī)器人怎么接線路 達(dá)亞電銷機(jī)器人官網(wǎng)

為了不讓域名fangyuanxiaozhan.com閑置, 作者又買了個(gè)國內(nèi)的虛擬主機(jī)(VPS)的ip為 111.230.254.173 , 用wordpress開了個(gè)博客網(wǎng)站, 由于vps的空間很大, 我就開了個(gè)私有網(wǎng)盤服務(wù), 由于日常開發(fā)需要用到git, 但又不想公開代碼, 我又開了個(gè)私有g(shù)it服務(wù)

我的vps掛了三個(gè)服務(wù), 分別是:

  1. WordPress搭建的博客服務(wù), 運(yùn)行于8000端口, 訪問方式 http://fangyuanxiaozhan.com:8000
  2. Gogs搭建的git服務(wù), 運(yùn)行于10080端口, 訪問方式 http://fangyuanxiaozhan.com:10080
  3. Nextcloud搭建的網(wǎng)盤服務(wù), 運(yùn)行于8080端口, 訪問方式 http://fangyuanxiaozhan.com:10080

我的需求:

  1. 1.訪問博客服務(wù)時(shí), 直接輸入 http://fangyuanxiaozhan.com
  2. 訪問git服務(wù)時(shí), 直接輸入 http://git.fangyuanxiaozhan.com
  3. 訪問網(wǎng)盤服務(wù)時(shí), 直接輸入 http://cloud.fangyuanxiaozhan.com

實(shí)現(xiàn)的方法

1、到托管域名的網(wǎng)站, 添加DNS解析, 我的域名 fangyuanxiaozhan.com 托管在阿里云, 我的做法是登錄 https://dns.console.aliyun.com/#/dns/domainList , 添加二級(jí)記錄

 

2、我使用的是centos7, nginx配置文件的默認(rèn)位置為 /etc/nginx/nginx.conf , 有意思的是, /etc/nginx/nginx.conf 內(nèi)引入了 配置文件夾 /etc/nginx/conf.d , 也就是我們可以把 /etc/nginx/nginx.conf 中的一些默認(rèn)配置注釋掉, 直接在文件夾 /etc/nginx/conf.d 中配置多個(gè)獨(dú)立的配置文件.

 

/etc/nginx/nginx.conf 的配置

# For more information on configuration, see:
#  * Official English Documentation: http://nginx.org/en/docs/
#  * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
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; 保證了 /etc/nginx/conf.d/ 下,所有以.conf結(jié)尾的配置文件, 都會(huì)被主配置文件 nginx.conf 引入并生效

/etc/nginx/conf.d/ 下面需要新建三個(gè)文件

 

blog.conf (實(shí)現(xiàn)8000端口映射到80端口, 不使用二級(jí)域名)

server { 
  listen 80;
  server_name fangyuanxiaozhan.com;

  location / {
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  Host   $http_host;
    proxy_pass     http://0.0.0.0:8000;
  }
}

blog.conf實(shí)現(xiàn)了fangyuanxiaozhan.com:8000映射到 fangyuanxiaozhan.com

git.conf (實(shí)現(xiàn)10080端口映射到80端口, 使用二級(jí)域名 git )

server { 
  listen 80;
  server_name git.fangyuanxiaozhan.com;

  location / {
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  Host   $http_host;
    proxy_pass     http://0.0.0.0:10080;
  }
}

git.conf實(shí)現(xiàn)了fangyuanxiaozhan.com:10080映射到 git.fangyuanxiaozhan.com

nc.conf (實(shí)現(xiàn)10080端口映射到80端口, 使用二級(jí)域名 cloud )

server { 
  listen 80;
  server_name cloud.fangyuanxiaozhan.com;

  location / {
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  Host   $http_host;
    proxy_pass     http://0.0.0.0:8080;
  }
}

git.conf實(shí)現(xiàn)了fangyuanxiaozhan.com:8080映射到 cloud.fangyuanxiaozhan.com

重啟nginx使配置生效

關(guān)閉nginx

sudo $(which nginx) -s stop

開啟nginx

sudo $(which nginx)

效果展示

 

 

 

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

標(biāo)簽:新鄉(xiāng) 楊凌 遼源 海東 湖南 黃石 衡水 南通

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《nginx配置二級(jí)域名的示例代碼》,本文關(guān)鍵詞  nginx,配置,二級(jí)域名,的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《nginx配置二級(jí)域名的示例代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于nginx配置二級(jí)域名的示例代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    沙洋县| 天峨县| 西林县| 海伦市| 平顺县| 大同县| 夏河县| 江达县| 昆明市| 黄梅县| 利津县| 辽中县| 阳朔县| 四子王旗| 理塘县| 鄂尔多斯市| 内江市| 海安县| 简阳市| 马公市| 石楼县| 英德市| 彰化市| 克什克腾旗| 郧西县| 安龙县| 灵台县| 宜春市| 清水河县| 沙坪坝区| 永仁县| 绵竹市| 鄱阳县| 大洼县| 陕西省| 通城县| 舟山市| 玛沁县| 日照市| 隆昌县| 额敏县|