0
点赞
收藏
分享

微信扫一扫

nginx 解析二级域名


1.   安装nginx

这个这里不多说了

sudo apt-get install nginx

即可

2.  指定一级域名到服务器(即默认端口80)

我这里使用本机模拟下二级域名

192.168.1.129    test.com
192.168.1.129    hcy.test.com

3. 到nginx的默认目录添加web1.conf

hcy@ubuntu:~$ cd /etc/nginx/sites-enabled/
hcy@ubuntu:/etc/nginx/sites-enabled$ ls
default_back web1.conf
hcy@ubuntu:/etc/nginx/sites-enabled$ vim web1.conf

 web1.conf 内容:

server {
listen 80;
server_name hcy.test.com;
# listen [::]:80 hcy.test.com;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/web1;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;


location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

4. 测试访问

分别访问 :test.com

分别访问 :hcy.test.com

 

nginx 解析二级域名_nginx

 

nginx 解析二级域名_php_02

举报

相关推荐

0 条评论