我刚开始在Ubuntu 10.04上探索Nginx。 我安装了Nginx,并且能够在本地主机上获得“Welcome to Nginx”页面。 但是,即使在站点可用/默认文件中进行更改,我也无法添加新的server_name。 尝试重新加载/重新启动Nginx,但没有任何工作。 一个有趣的观察。 浏览器中的“ http:// mycomputername ”工作。 所以不知何故有一个像“server_name $ hostname”这样的命令可以覆盖我的规则。
File:sites-available / mine.enpass
server { listen 80; server_name mine.enpass ; access_log /var/log/nginx/localhost.access.log; location / { root /var/www/nginx-default; index index.html index.htm; } }
文件:nginx.confg
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_comp_level 2; gzip_proxied any; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
我的build议是通过删除/ etc / nginx / sites-enabled中的符号链接来删除默认网站:
$ sudo rm /etc/nginx/sites-enabled/default
然后在一个新文件中创build你想要的configuration,称之为/etc/nginx/sites-available/your.host.name。 假设你的主页在/var/www/your.host.name,这里有一个非常简单的例子:
server { listen 80; server_name your.host.name; location / { root /var/www/your.host.name; index index.html; } }
然后在/ etc / nginx / sites-enabled中创build一个符号链接:
$ sudo ln -s /etc/nginx/sites-available/your.host.name /etc/nginx/sites-enabled/your.host.name
最后重启nginx:
$ sudo /etc/init.d/nginx restart
祝你好运。
尝试更改server_name mine.enpass ; 到server_name mine.enpass; 在您的网站 – 可用/ mine.enpass文件
是否有可能你没有将mine.enpass添加到你的/etc/hosts文件中?
这是我所犯的基本错误,与nginx有相同的问题,但在OSX(偶然发现这里的解决scheme)