Nginx服務(wù)器綁定域名

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 {
    #說明監(jiān)聽80端口
    listen       80;

    #訪問的域名,多個(gè)域名用空格隔開
    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 / {
        #將請(qǐng)求代理到配置的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服務(wù)
sudo systemctl start nginx.service #啟動(dòng)
sudo systemctl restart nginx.service #重啟
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,506評(píng)論 19 139
  • 本文所介紹的環(huán)境是:操作系統(tǒng):CenOS-7-x86_64環(huán)境:虛擬機(jī)Nginx 版本:1.6.3 一、Nginx...
    FlySheep_ly閱讀 9,073評(píng)論 1 40
  • 第一章 Nginx簡(jiǎn)介 Nginx是什么 沒有聽過Nginx?那么一定聽過它的“同行”Apache吧!Ngi...
    JokerW閱讀 33,009評(píng)論 24 1,002
  • Page 1:nginx 服務(wù)器安裝及配置文件詳解 CentOS 6.2 x86_64 安裝 nginx 1.1 ...
    xiaojianxu閱讀 8,664評(píng)論 1 41
  • 小雨象輕紗 飄來飄去 撫抹著大地 小雨象藕絲 扯扯不斷 牽念著云朵 小雨也有情思 心中裝滿了憂慮 擔(dān)心云朵被風(fēng)刮走...
    吉羊玉奕v閱讀 677評(píng)論 6 26

友情鏈接更多精彩內(nèi)容