麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 網(wǎng)站 > Nginx > 正文

nginx配置二級域名的示例代碼

2024-08-30 12:29:48
字體:
供稿:網(wǎng)友

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

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

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

我的需求:

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

實現(xiàn)的方法

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

nginx,二級域名,代碼

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 中配置多個獨立的配置文件.

nginx,二級域名,代碼

/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é)尾的配置文件, 都會被主配置文件 nginx.conf 引入并生效

在 /etc/nginx/conf.d/ 下面需要新建三個文件

nginx,二級域名,代碼

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

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實現(xiàn)了fangyuanxiaozhan.com:8000映射到 fangyuanxiaozhan.com

git.conf (實現(xiàn)10080端口映射到80端口, 使用二級域名 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實現(xiàn)了fangyuanxiaozhan.com:10080映射到 git.fangyuanxiaozhan.com

nc.conf (實現(xiàn)10080端口映射到80端口, 使用二級域名 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實現(xiàn)了fangyuanxiaozhan.com:8080映射到 cloud.fangyuanxiaozhan.com

重啟nginx使配置生效

關(guān)閉nginx

sudo $(which nginx) -s stop

開啟nginx

sudo $(which nginx)

效果展示

nginx,二級域名,代碼

nginx,二級域名,代碼

nginx,二級域名,代碼

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到服務(wù)器教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 成年免费视频黄网站在线观看 | 欧美中文字幕一区二区三区亚洲 | 国产精品自拍99 | 黄色一级毛片免费看 | 亚洲影视中文字幕 | 久久亚洲精品国产一区 | 免费a视频在线观看 | 特黄一区二区三区 | 中文字幕精品在线播放 | 中文日产幕无线码6区免费版 | 日日草夜夜草 | 色婷婷久久久亚洲一区二区三区 | 亚洲一区二区在线视频 | 国产九色在线观看 | 密室逃脱第一季免费观看完整在线 | 性爱在线免费视频 | 久久性生活免费视频 | 色视频91 | 狠狠操操 | 国产亚洲精品yxsp | 911精品影院在线观看 | 免费黄色大片网站 | 噜噜噜影院 | 国产三级三级三级三级 | 国产成人在线一区二区 | 在线日韩亚洲 | 国产91在线高潮白浆在线观看 | 欧美大逼网 | 国产一区二区三区影视 | 伊人网站 | 国产精品久久久久一区二区 | 大西瓜永久免费av在线 | 久久色网站| 国产成人在线一区 | 久久艳片| 毛片a级毛片免费播放100 | 欧美爱爱视频免费看 | 国产毛片在线看 | 欧美 videos粗暴 | 九九热九九 | av电影免费观看 |