虚拟主机不工作
我在nginxubuntu中创建了一个虚拟主机,例如example.com但当我转到example.com时,它显示了原始的example.com
这是一个虚拟主机文件/etc/nginx/sites-enabled/example.com
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/example.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
这是nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
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 TLSv1.3; # 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_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/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
nginx版本:nginx/1.18.0(Ubuntu(
Ubuntu版本
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
您可能需要将example.com放在/etc/hosts文件中:
127.0.0.1 example.com
这将否决为realexample.com设置的DNS,并将使您的计算机转到本地版本,而不是原始
sudo echo '127.0.0.1 example.com' >> /etc/hosts
在/etc/nginx/sites-available/
中创建example.com
文件,并将以下内容放入中
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/example.com/;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
}
现在将此文件符号链接到/etc/nginx/sites-enabled/example.com
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
重新启动nginx后应该可以工作了。
nginx -s reload
对于任何调试:
nginx -t