Nginx 多域名配置的方法

2025-05-26 0 68

很多情况下,需要使用多个域名,但你只有一台服务器,那如何搭建,让一台服务器可以访问对个域名,下面的方法是在服务器上搭建Nginx, 直接修改其配置,如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85
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搭建和配置过程如果有疑问的,可以查看另一篇文章:http://www.zzvips.com/article/36760.html

注意:这里的域名,一定要和你备案的域名完全一致,否则配置失败,会调用默认index.html的内容,或者直接无法启动Nginx。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。

原文链接:http://blog.csdn.net/hutianyou123/article/details/77745753

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 Nginx 多域名配置的方法 https://www.kuaiidc.com/53431.html

相关文章

发表评论
暂无评论