1. 程式人生 > >Apache和nginx 域名配置

Apache和nginx 域名配置

php etc spa ram 主機 地址 增加 localhost symlink

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 前面得分號

Apache和nginx 域名配置