1. 程式人生 > >LNMP-Nginx默認虛擬主機

LNMP-Nginx默認虛擬主機

nginx

與httpd類似,第一個被Nginx加載的虛擬主機就是默認主機。但與之不同的是,它還有一個配置用來標記默認虛擬主機。

1、編輯nginx.conf

[[email protected] conf]# vi /usr/local/nginx/conf/nginx.conf
        location ~ \.php$
        {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/php-fcgi.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
        }
    }
include vhost/*.conf;   ##增加改行
}

2、編輯default.conf

[[email protected] conf]# mkdir /usr/local/nginx/conf/vhost
[[email protected] conf]# cd !$;vi default.conf
server
{
    listen 80 default_server;  
    server_name aaa.com;
    index index.html index.htm index.php;
    root /data/wwwroot/default;
}

3、檢查與啟動

[[email protected]
/* */ vhost]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [[email protected] vhost]# /usr/local/nginx/sbin/nginx -s reload

4、測試效果

[[email protected] vhost]# mkdir -p /data/wwwroot/default/
[[email protected]
/* */ vhost]# echo “This is a default site.”>/data/wwwroot/default/index.html [[email protected] vhost]# curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> [[email protected] vhost]# curl -x127.0.0.1:80 123.com “This is a default site.”


本文出自 “Gorilla City” 博客,請務必保留此出處http://juispan.blog.51cto.com/943137/1955284

LNMP-Nginx默認虛擬主機