w w w . w d . c h a t
🗣 Wd提问
nginx配置网址如何配置一个或多个
🤖 Ai回答
Nginx 配置网址(一个或多个)指南

Nginx 可以通过 server 块配置一个或多个网址(域名)。以下是配置方法:

单个网址配置

nginx
server {
listen 80;
server_name example.com; 你的域名

location / {
root /var/www/example.com; 网站文件目录
index index.html index.htm;
}
}

多个网址配置

方法1:多个 server 块

nginx
server {
listen 80;
server_name example.com;

location / {
root /var/www/example.com;
index index.html index.htm;
}
}

server {
listen 80;
server_name another.com;

location / {
root /var/www/another.com;
index index.html index.htm;
}
}

方法2:一个 server 块多个域名

nginx
server {
listen 80;
server_name example.com another.com third.com;

location / {
root /var/www/shared; 所有域名共享同一目录
index index.html index.htm;
}
}

HTTPS 配置(SSL证书)

nginx
server {
listen 443 ssl;
server_name example.com;

ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;

location / {
root /var/www/example.com;
index index.html index.htm;
}
}

常用配置选项

1、重定向 HTTP 到 HTTPS:
nginx
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}

2、配置子域名:
nginx
server {
listen 80;
server_name sub.example.com;

location / {
root /var/www/sub.example.com;
index index.html index.htm;
}
}

3、配置通配符域名:
nginx
server {
listen 80;
server_name *.example.com;

location / {
root /var/www/wildcard;
index index.html index.htm;
}
}

配置完成后,记得测试并重新加载 Nginx:
bash
sudo nginx t 测试配置
sudo systemctl reload nginx 重新加载配置
0
📍
IP地址 214.189.49.189
🔍
搜索次数 8
提问时间 2025-07-03 17:09:29

📣 商家广告

取名

取名

域名评估

域名评估

温泉规划公司

温泉规划公司

🛒 域名购买

热门提问

🌐 域名评估

最新挖掘

🖌 热门作画

🤝 关于我们

🗨 加入群聊
💬选择任意群聊,与同好交流分享

🔗 友情链接

🧰

站长工具

📢

温馨提示

本站所有 ❓️ 问答 由Ai自动创作,内容仅供参考,若有误差请用"联系"里面信息通知我们人工修改或删除。

👉

技术支持

本站由 🟢 豌豆Ai 提供技术支持,使用的最新版: 《豌豆Ai站群搜索引擎系统 V.25.10.25》 搭建本站。

上一篇 354930 354931 354932 下一篇