修改 ngnix.conf
- 注释掉:server 节点
- 添加
include conf.d/*.conf;需要在/usr/local/etc/nginx创建目录conf.d - 在http 节点下添加 ·include conf.d/*.conf;
- 在
/usr/local/var/www/创建两个站点- test.com
- me.com
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;pid logs/nginx.pid;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;#include /etc/nginx/conf.d/*.conf; #加入多站点配置#server {#listen 80;# server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;#location / {#root /usr/local/var/www/;#index index.html index.htm;#}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html##error_page 500 502 503 504 /50x.html;#location = /50x.html {#root html;#}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}#}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}include conf.d/*.conf;#include servers/*;}
添加主机配置
- test.com.conf
server {
listen 80;
server_name test.com;
charset utf-8;
root /usr/local/var/www/test.com/;
location / {
index index.html index.htm ;
}
}
- me.com
server {
listen 80;
server_name me.com;
charset utf-8;
root /usr/local/var/www/me.com/;
location / {
index index.html index.htm;
}
}
添加hosts
在 /usr/etc/hosts
127.0.0.1 me.com
127.0.0.1 test.com
重启 nginx
sudo nginx -s reload
配置完成
浏览器中访问可以了
指定端口部署
指定端口部署配置和前面的没有啥区别,指定端口后就不要指定 hosts 绑定域名
指定一个 8888 的网站
配置名为 mutiport.conf
server {
listen 8888; #端口好
server_name mutiport;
charset utf-8;
root /usr/local/var/www/mutiport/;
location / {
index index.html index.htm;
}
}
配置保存之后就可以 127.0.0.1:8888 访问网站了
