【发布时间】:2023-04-01 17:33:02
【问题描述】:
我使用 nginx 设置了一个虚拟服务器,并有一个nginx.conf 文件如下,它适用于http://localhost 和http://localhost:100 上的两个不同网站:
user nobody;
worker_processes 1;
error_log /usr/local/Cellar/nginx/1.4.6/logs/error.log;
pid /usr/local/Cellar/nginx/1.4.6/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include /usr/local/etc/nginx/mime.types;
include /usr/local/etc/nginx/fastcgi.conf;
default_type application/octet-stream;
access_log /usr/local/var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
access_log /usr/local/Cellar/nginx/1.4.6/logs/localhost.access.log combined;
location / {
root /Users/apiah/Websites/greenapple;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /Users/apiah/Websites/greenapple;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/apiah/Websites/greenapple$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 100;
server_name localhost;
access_log /usr/local/Cellar/nginx/1.4.6/logs/localhost.access.log combined;
location / {
root /Users/apiah/Websites/blueweb;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /Users/apiah/Websites/blueweb;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Users/apiah/Websites/blueweb$fastcgi_script_name;
include /usr/local/etc/nginx/fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
我喜欢在同一个端口 80 http://localhost 上测试上述两个(或更多)网站。例如,假设我们有三个文件夹,分别称为 blueweb、redweb 和 greenweb,所以我希望能够在转到 http://localhost 时看到所有三个文件夹,然后从那里选择转到 @987654330 @、http://localhost/redweb 或 http://localhost/greenweb。您能否查看nginx.conf 文件并将您的cmets 给我?
【问题讨论】:
标签: nginx localhost virtualhost