Apache和nginx 域名配置

apache配置

.hosts配置:

1.用编辑器打开hosts文件,位置:C:\Windows\System32\drivers\etc目录下

2.hosts文件里添加自己的域名配置,配置规则如下:

127.0.0.1 域名1

127.0.0.1 域名2

..........

.apache配置:

1.编辑httpd.conf文件,开启虚拟主机,位置:在apache的安装目录,即phpstudy安装目录下的phpStudy\Apache\conf,找到Include conf/extra/httpd-vhosts.conf,去掉前面的#

2.进入开启的虚拟主机文件httpd-vhosts.conf进行域名配置,位置:\phpStudy\Apache\conf\extra目录下

配置规则:
# localhost 默认的
<VirtualHost *:80>
    DocumentRoot "F:\GZJ\www"
    ServerName localhost
    ServerAlias
  <Directory "F:\GZJ\www">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
      Require all granted
  </Directory>
</VirtualHost>

新配置的
<VirtualHost *:80>
    DocumentRoot "F:\GZJ\www\datong"           地址
    ServerName dt.cn    域名
    ServerAlias
  <Directory "F:\GZJ\www\datong">
      Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
      Require all granted
  </Directory>
</VirtualHost>

 

nginx配置

Nginx  -t 查看nginx配置的正确性

配置host

1cd /etc/hosts

增加自定义域名127.0.0.1 自定义域名”     对应conf.d下的server_name的值

2直接复制nginx下的sites-enabled下的default con.d目录下新命名一个你需要的名字;(每个域名 在conf.d目录下配置一个新配置文件来对应每个域名)

3设置nginx下的conf.d 下刚刚自定义.conf 文件 内容如下:(配置根据自己存放地址等不同)

Server{

Listen 80;

Root (后面跟上项目地址);

Index index.php;

Server_name (配置得域名 和/etc/hosts)里添加得域名要一致;

Location / {

Try_files $uri $uri/ =404;

}

Location  ~  \.php {

Root  (后面跟上项目地址);

Include fastcgi.conf;

Fastcgi_index index.php;

Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

Fastcgi_pass unix:/run/php/php7.o-fpm.sock;

}

}

配置这些前 先到php里面去掉分号

路径 /etc/php/7.0/fpm/pool.d/www.conf

去掉 listen = /var/run/php/php7.0-fpm.sock 前面得分号

 

 

 

相关文章