自由空间——xukzhao.ga

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 13|回复: 0

nginx 多个站点配置

[复制链接]

22

主题

13

回帖

276

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
276
发表于 2021-5-12 14:12:31 | 显示全部楼层 |阅读模式
服务器地址:192.168.1.231
域名:test1.com 目录:/www/ test1.com
域名:test2.com 目录: /www/ test2.com
该配置思路
把2个站点   test1.com,   test2.com  放到 nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件   test1.com.conf, test2.com.conf, 并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx

实际操作:
  1. mkdir /www/test1.com

  2. mkdir /www/test2.com
  3. cd /etc/nginx/

  4. mkdir vhosts

  5. cd vhosts/

  6. vi test1.com.conf
复制代码

#增加以下内容
  1. server {

  2.         listen  80;

  3.         server_name  test1.com www.test1.com;

  4.         access_log  /www/access_test1.log  main;

  5.         location / {

  6.             root   /www/test1.com;

  7.             index  index.php index.html index.htm;

  8.         }

  9.         error_page   500 502 503 504  /50x.html;

  10.         location = /50x.html {

  11.             root   /usr/share/nginx/html;

  12.         }

  13.        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

  14.         location ~ .php$ {

  15.             fastcgi_pass   127.0.0.1:9000;

  16.             fastcgi_index  index.html;

  17.             fastcgi_param  SCRIPT_FILENAME  /www/test1.com/$fastcgi_script_name;

  18.             include        fastcgi_params;

  19.         }

  20.         location ~ /.ht {

  21.             deny  all;

  22.         }

  23. }
复制代码

[root@localhost vhosts]# vi test2.com.conf
#增加以下内容
  1. server {

  2.         listen  80;

  3.         server_name  test2.com www.test2.com;



  4.         access_log  /www/access_test2.log  main;



  5.         location / {

  6.             root   /www/test2.com;

  7.             index  index.php index.html index.htm;

  8.         }



  9.         error_page   500 502 503 504  /50x.html;

  10.         location = /50x.html {

  11.             root   /usr/share/nginx/html;

  12.         }



  13.        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

  14.         location ~ .php$ {

  15.             fastcgi_pass   127.0.0.1:9000;

  16.             fastcgi_index  index.html;

  17.             fastcgi_param  SCRIPT_FILENAME  /www/test2.com/$fastcgi_script_name;

  18.             include        fastcgi_params;

  19.         }



  20.         location ~ /.ht {

  21.             deny  all;

  22.         }

  23. }
复制代码

修改nginx.conf
备份配置文件

  1. cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf20160425

  2. vi /etc/nginx/nginx.conf.
复制代码

#修改成以下内容
  1. user  nginx;

  2. worker_processes  1;



  3. # main server error log

  4. error_log       /var/log/nginx/error.log ;

  5. pid     /var/run/nginx.pid;

  6. events {

  7.         worker_connections  1024;

  8. }

  9. # main server config

  10. http {

  11.         include       mime.types;

  12.         default_type  application/octet-stream;

  13.         log_format  main  '$remote_addr - $remote_user [$time_local] $request '

  14.                       '"$status" $body_bytes_sent "$http_referer" '

  15.                       '"$http_user_agent" "$http_x_forwarded_for"';

  16.         sendfile        on;

  17.         #tcp_nopush     on;

  18.         #keepalive_timeout  0;

  19.         keepalive_timeout  65;

  20.         gzip  on;

  21.         server {

  22.                 listen         80;

  23.                 server_name     _;

  24.                 access_log      /var/log/nginx/access.log main;

  25.                 server_name_in_redirect  off;

  26.                 location / {

  27.                         root  /usr/share/nginx/html;

  28.                         index index.html;

  29.                 }

  30.         }
复制代码



重起nginx服务

  1. service nginx restart
复制代码




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|自由空间

GMT+8, 2025-7-20 23:10 , Processed in 0.627554 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表