我今天读了很多关于这个的文章,但我不明白我做错了什么。我正在尝试使用一个带有 nginx 的 vps 将两个网站(site1.com、site2.com)放在一起。
这是我的 nginx.conf
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
conf.d 目录是空的,并且在启用站点的目录中有我的配置:
server {
listen 80 default;
root /home/site1/www;
access_log /home/site1/logs/nginx.access.log;
server_name site1.com;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
和
server {
listen 80;
root /home/site2/www;
access_log /home/site2/logs/nginx.access.log;
server_name site2.com;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
当然 /home/site1/www 和 /home/site2/www 都包含网站文件。
现在,如果我尝试打开 site1.com,这很有趣:
我得到:无法打开 site1.com:81 错误
我究竟做错了什么?为什么这个 81 端口会添加到 URL 中?