ubuntu 在本地设置域名

本文介绍如何通过编辑/etc/hosts文件将域名映射到本地,并配置Nginx以实现本地环境下的域名访问。首先修改hosts文件添加所需域名,然后重启网络服务;接着配置Nginx虚拟主机,设置域名监听及根目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自己学习,记录下来,仅供参考,高手就跳过吧
第一步:
sudo vim /etc/hosts
127.0.0.1   localhost
127.0.1.1   allen
#本地调试用的

127.0.0.1   www.example.com(你想要的域名)
# The following lines are desirable for IPv6 capablehosts
::1     ip6-localhostip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

sudo /etc/init.d/networking restart

第二步:
首先 看看我的nginx配置
user  allen allen;
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;
    //虚拟主机的配置,这样vhosts文件夹包含一个个文件,每一个文件都是一个站点
    include vhosts/*;
}
如下 example.conf
server {
       listen      80;
       server_name www.example.com;
       location / {
       root   /data/www/wwwroot/typecho/;
          indexindex.php  index.html index.htm;
       }
       error_page   500 502 503 504 /50x.html;
       location = /50x.html {
           root  html;
       }

       location ~ \.php* {
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME /data/www/wwwroot/typecho$fastcgi_script_name;
           include      fastcgi_params;
       }
    }
这样设置就是我把本地typecho应用的域名设置www.example.com

转自:http://blog.youkuaiyun.com/shujuliu818/article/details/47065917
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值