我有一个nginx.conf文件,看起来像这样:
http { server { listen 80; server_name myapp.org; return 301 http://www.myapp.org$request_uri; } server { listen 80; server_name www.myapp.org; passenger_enabled on; root /var/www/myapp/current/public; } }
这似乎是这个网站和其他人build议的格式,但是当我去myapp.org,我只是从nginx得到这个消息:
欢迎来到nginx!
如果你看到这个页面,nginx web服务器已经成功安装并正常工作。 需要进一步的configuration。
- 在NGINX中,通过301子域redirect到URI / URLconfiguration错误
- cname与301名称redirect
- DNSredirect到网站目录
- WordPress非www到wwwredirect循环在NginX中
- 301redirect一个URL很长的短划线
有关在线文档和支持,请参阅nginx.org。 商业支持可在nginx.com上find。
感谢您使用nginx。
虽然如果我去www.myapp.org,那么一切都按预期工作。 为什么不redirect?
更新:
nginx.conf:
user www-data; worker_processes 4; pid /var/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; # passenger_friendly_error_pages on; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # 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/x-javascript text/xml application/xml application/xml+rss text/javascript; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## # include /etc/nginx/naxsi_core.rules; ## # Phusion Passenger config ## # Uncomment it if you installed passenger or passenger-enterprise ## passenger_root /home/deploy/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/passenger-5.0.4; passenger_ruby /home/deploy/.rbenv/versions/2.0.0-p247/bin/ruby; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; server { listen 80; server_name coolthearth.net; return 301 http://www.cooltheearth.org$request_uri; } server { listen 80; server_name www.coolthearth.net; return 301 http://www.cooltheearth.org$request_uri; } server { listen 80; server_name coolthearth.org; return 301 http://www.cooltheearth.org$request_uri; } server { listen 80; server_name www.cooltheearth.org; passenger_enabled on; root /var/www/rails_backend/current/public; } } # 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; # } # }
在/ etc / nginx的/启用的站点 – /默认
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /usr/share/nginx/www; index index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /doc/ { alias /usr/share/doc/; autoindex on; allow 127.0.0.1; deny all; } }
您的server_name指令中有错别字。
你写了coolthearth而不是cooltheearth在3个地方。
用错字testing当前设置给出:
curl -H "Host: coolthearth.org" "http://104.131.135.243" -I HTTP/1.1 301 Moved Permanently Server: nginx/1.6.2 Date: Fri, 20 Mar 2015 22:22:51 GMT Content-Type: text/html Content-Length: 184 Connection: keep-alive Location: http://www.cooltheearth.org/
修复这些,它会工作。