本篇內容主要講解“Nginx多域名配置方法介紹”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Nginx多域名配置方法介紹”吧!
很多情況下,需要使用多個域名,但你只有一臺服務器,那如何搭建,讓一臺服務器可以訪問對個域名,下面的方法是在服務器上搭建Nginx, 直接修改其配置,如下:
user www www; #用戶名稱
worker_processes 2;
error_log ../error.log;
#error_log logs/error.log notice;
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#第一個域名服務
server
{
listen 80;#監聽端口
server_name website1.com;#服務器網址
root /usr/local/nginx/html;#站點目錄
index test.html test.htm test.php;#網址文件
}
#第二個域名服務
server {
listen 80;
server_name website1.com;
location / {
#location 可以不寫,也可以寫;但如果需要做更詳細的配置,需要利用location
root /usr/local/nginx/html1;#站點目錄,可以自行定義
index x264.html; }
}
#禁止通過服務器IP地址訪問
server
{
listen 80 default_server;
server_name _;
return 403;
}
#允許IP地址對應的域名訪問
server
{
listen 80 default;
server_name _;
return 500;
}
}對上述Nginx搭建和配置過程如果有疑問的,可以查看另一篇文章:https://www.jb51.net/article/122603.htm
注意:這里的域名,一定要和你備案的域名完全一致,否則配置失敗,會調用默認index.html的內容,或者直接無法啟動Nginx。
到此,相信大家對“Nginx多域名配置方法介紹”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。