我有一个静态IP和2个域名(beryju.org和nope.berlin)在我的VPS的nginx设置。
我想服务:
另外我想要beryju.org和blog.beryju.org支持SSL。
但是用我目前的configuration,我得到:
我试过了,当我从listen语句中删除主机名时也不起作用
listen i.beryju.org:80;
至
listen 80;
在每个文件中。
server { listen blog.beryju.org:80; listen blog.beryju.org:443 ssl; ssl_certificate /home/beryju/SSL/nginx/beryju.org.cert; ssl_certificate_key /home/beryju/SSL/nginx/beryju.org.key; access_log /var/log/nginx/beryjuorg-blog.access.log; error_log /var/log/nginx/beryjuorg-blog.error.log; root /home/beryju/Apps/Ghost/; index index.html index.htm index.php; location / { proxy_pass http://127.0.0.1:2368; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
server { listen i.beryju.org:80; server_name i.beryju.org; access_log /var/log/nginx/beryjuorg-image-hoster.access.log; error_log /var/log/nginx/beryjuorg-image-hoster.error.log; root /usr/share/nginx/i.beryju.org; index index.html index.htm index.php; location /gyazo.php { try_files $uri $uri/ =404; fastcgi_index index.php; include fcgi.conf; fastcgi_pass unix:/var/run/php-fcgi-beryjuorg-image-hoster-php-fcgi-0.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location / { try_files $uri $uri/ =404; } }
server { listen beryju.org:80; listen beryju.org:443 ssl; ssl_certificate /home/beryju/SSL/nginx/beryju.org.cert; ssl_certificate_key /home/beryju/SSL/nginx/beryju.org.key; server_name beryju.org; access_log /var/log/nginx/beryjuorg.access.log; error_log /var/log/nginx/beryjuorg.error.log; root /usr/share/nginx/beryju.org/; index index.html index.htm index.php; location ~ [^/]\.php(/|$) { fastcgi_index index.php; include fcgi.conf; fastcgi_pass unix:/var/run/php-fcgi-beryjuorg-php-fcgi-0.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
server { listen nope.berlin:80; server_name nope.berlin; access_log /var/log/nginx/nopeberlin.access.log; error_log /var/log/nginx/nopeberlin.error.log; root /usr/share/nginx/nope.berlin/; index index.html index.htm index.php; location / { autoindex on; } }
文件beryjuorg-blog.conf中缺less一个server_name指令,这意味着服务器块将成为没有HTTP / 1.1主机头(域名)或未定义的主机头的请求。 请参阅nginx如何处理请求和服务器块以了解更多信息。
既然你有一个静态的IP地址,你可以通过将IP地址添加到listen指令来使configuration更加明确,例如
listen 192.168.0.3:80;
listen指令并不意味着接受主机名; 请参阅文档。
同时指定server_name和一个可选的IP地址来解决问题。