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 #重启

你可能感兴趣的:(Nginx服务器绑定域名)