nginx将xxx.com重定向到www.xxx.com配置

Nginx域名配置

对于想搭建自己博客或者其他个人网站的小伙伴,可能会需要配置域名。

在我们购买完服务器,代码敲完,项目搞定,怎么使用域名访问呢?

首先购买域名(要有DNS解析)-> 然后域名备案与审核 -> 最后将域名与自己服务器的ip挂载上。

最后,执行nginx配置,在保证通过ip可以访问地址时,在nginx更新以下配置即可。注意端口。


worker_processes  1;

events {
    worker_connections  ;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  ;

    server {
        listen       ;
        server_name  www.xxx.com;
		charset utf-8;

		location / {
            root   C:\data\project\ui;
			try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }
		
        error_page     /50x.html;
        location = /50x.html {
            root   html;
        }
    }
	
}
原文链接:,转发请注明来源!