我在 Raspberry Pi 上安装了 nginx 来做一些简单的开发工作。/etc/gninx/sites-available 中有 3 个文件,它们也符号链接到 /etc/nginx/sites-enabled。它们目前有直接的设置。
Example.com 具有以下内容:
server {
listen 80;
root /var/www/example.com;
server_name example.com;
location / {
try_files $uri $uri/ =404;
}
}
另外 2 个网站的设置相同,只是根目录和 server_name 不同。
我已在本地计算机上更新了 /etc/hosts 文件,因此当我使用浏览器访问 example.com 或其他 2 个网站时,不会出现无法找到该网站的问题。但是,它们都显示默认的 debian nginx 页面。
nginx.conf 包含以下内容:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
# include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
error_log /var/log/nginx/error.log warn;
答案1
如果您尝试在 nginx 配置文件中搜索“VirtualHost *:80”标签,那么我的答案是您找不到它。VirtualHost 用于 apache 服务器。在 nginx 中,它由“server { listen 80;”表示。