Nginx 多域名配置的方法
很多情况下,需要使用多个域名,但你只有一台服务器,那如何搭建,让一台服务器可以访问对个域名,下面的方法是在服务器上搭建Nginx,直接修改其配置,如下:
userwwwwww;#用户名称 worker_processes2; error_log../error.log; #error_loglogs/error.lognotice; pid/usr/local/nginx/nginx.pid; worker_rlimit_nofile65535; events { useepoll; worker_connections65535; } http { includemime.types; default_typeapplication/octet-stream; log_formatmain'$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent""$http_x_forwarded_for"'; #access_loglogs/access.logmain; server_names_hash_bucket_size128; client_header_buffer_size32k; large_client_header_buffers432k; client_max_body_size8m; sendfileon; tcp_nopushon; keepalive_timeout60; tcp_nodelayon; fastcgi_connect_timeout300; fastcgi_send_timeout300; fastcgi_read_timeout300; fastcgi_buffer_size64k; fastcgi_buffers464k; fastcgi_busy_buffers_size128k; fastcgi_temp_file_write_size128k; gzipon; gzip_min_length1k; gzip_buffers416k; gzip_http_version1.0; gzip_comp_level2; gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml; gzip_varyon; #第一个域名服务 server { listen80;#监听端口 server_namewebsite1.com;#服务器网址 root/usr/local/nginx/html;#站点目录 indextest.htmltest.htmtest.php;#网址文件 } #第二个域名服务 server{ listen80; server_namewebsite1.com; location/{ #location可以不写,也可以写;但如果需要做更详细的配置,需要利用location root/usr/local/nginx/html1;#站点目录,可以自行定义 indexx264.html;} } #禁止通过服务器IP地址访问 server { listen80default_server; server_name_; return403; } #允许IP地址对应的域名访问 server { listen80default; server_name_; return500; } }
对上述Nginx搭建和配置过程如果有疑问的,可以查看另一篇文章:https://www.nhooo.com/article/122603.htm
注意:这里的域名,一定要和你备案的域名完全一致,否则配置失败,会调用默认index.html的内容,或者直接无法启动Nginx。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。