我想将我的服务器的IP重写为域名url,但我最难找出如何实现这一点。重写 - 将服务器IP转发到域名网址nginx
例如,当我在浏览器中输入213.34.54.xxx时,我希望它被重写为mydomain.com而不显示IP地址。
我现在的配置如下:
/etc/nginx/nginx.conf
user www-data;
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
server_names_hash_bucket_size 64;
sendfile on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/mydomain;
}
的/ etc/nginx的/启用的站点 -/MYDOMAIN
upstream unicorn {
server unix:/tmp/unicorn.mydomain.sock fail_timeout=0;
}
server {
listen 80 default;
server_name localhost;
root /home/deployer/apps/mydomain/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
我试过把这个添加到服务器指令中mydomain配置文件:
rewrite^$scheme://mydomain.com$request_uri redirect;
但我的浏览器中出现了太多的REDIRECTS错误。
最起码,我能够防止IP地址显示在服务器指令,使用此:
if ($host !~* ^www\.) {
rewrite ^(.*)$ http://www.$host$1 permanent;
}
然而,这个被列为nginx的网站上的缺陷之一:(
什么,我可能是做错了任何见解将不胜感激!
谢谢!
不工作,重定向太多 – tgdn 2016-04-25 15:06:42