Nginx服务器绑定域名

1. 安装Nginx

# CentOS
yum install nginx;
# Ubuntu
sudo apt-get install nginx;
# Mac
brew install nginx;

2. 打开文件夹

/etc/nginx/conf.d

3. 新建文件

image.png

4. 添加域名绑定

server {
 server {
    #说明监听80端口
    listen       80;

    #访问的域名,多个域名用空格隔开
    server_name  qiuzhilin.com.cn www.qiuzhilin.com.cn *.qiuzhilin.com.cn;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    charset utf8;

    location / {
        #将请求代理到配置的8080端口上
        root   /home/qiuzhilin/www/qiuzhilin.com.cn;
        index   index.html;
    }
    
    location /api {
        proxy_pass http://127.0.0.1:3002/;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect http://$host:8080/ http://$host:$server_port/; 
  }
    #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   /usr/share/nginx/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;
    #}
}
}
  1. 重启Nginx服务
sudo systemctl start nginx.service #启动
sudo systemctl restart nginx.service #重启
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,159评论 19 139
  • 本文所介绍的环境是:操作系统:CenOS-7-x86_64环境:虚拟机Nginx 版本:1.6.3 一、Nginx...
    FlySheep_ly阅读 12,912评论 1 40
  • 第一章 Nginx简介 Nginx是什么 没有听过Nginx?那么一定听过它的“同行”Apache吧!Ngi...
    JokerW阅读 32,929评论 24 1,002
  • Page 1:nginx 服务器安装及配置文件详解 CentOS 6.2 x86_64 安装 nginx 1.1 ...
    xiaojianxu阅读 12,724评论 1 41
  • 小雨象轻纱 飘来飘去 抚抹着大地 小雨象藕丝 扯扯不断 牵念着云朵 小雨也有情思 心中装满了忧虑 担心云朵被风刮走...
    吉羊玉奕v阅读 3,823评论 6 26

友情链接更多精彩内容