我在EC2实例上运行Nginx。 我有一个网页安装在默认的/usr/share/nginx/html目录中。 我注意到,如果我使用AMI创build一个EC2实例的AMI和一个新的EC2实例,默认的Nginx欢迎站点(即index.html,404.html等)被恢复并覆盖我现有的网站这些文件是一样的。 我可以通过在那个目录中做一个git status来看这个,看看他们已经被添加了。
这有点痛苦,因为我在EC2实例上运行一个SaaS产品,让客户看到Nginx的欢迎页面看起来有些不专业。
我的问题是:这可能是什么原因造成的?
这是我的nginx.conf :
# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes 1; error_log /var/log/nginx/error.log; #error_log /var/log/nginx/error.log notice; #error_log /var/log/nginx/error.log info; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; #server { # listen 80; # server_name *.xxx.com; # return 301 https://$host$request_uri; #} server { listen 80; listen 443 default ssl; server_name *.xxx.com; if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; } ssl_certificate /etc/pki/tls/certs/process.st.crt; ssl_certificate_key /etc/pki/tls/private/process.st.key; ssl_protocols SSLv3 TLSv1; ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; # Disable cache (for now). add_header Cache-Control no-cache; } # redirect server error pages to the static page /40x.html # error_page 404 /404.html; location = /40x.html { root /usr/share/nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
我做了创build基本AMI图像的步骤。
sudo yum install git , sudo yum install nginx 。 /etc/nginx/nginx.conf到上面。 /usr/share/nginx/html默认页面。 /usr/share/nginx/html 。 现在我创build图像:
ec2-create-image $INSTANCE_ID --name base 。 我只是花时间来试图重现这个问题,并没有办法。
我推出了最新的Amazon Linux AMI。
login后,我通过yum安装了git和nginx,将/usr/share/nginx/html到/usr/share/nginx/orig-html ,将一个html repo克隆到usr/share/nginx/html ,回购是可见的,而不是testing页面。
然后,我使用AWS Console从工作实例中“创build映像”。
AMI映像完成后,我从自定义AMI启动了另一个实例,并确认我已安装的网站正在运行,而不是默认的网站。
所以我想我会问你是否正确创build图像,等待快照完成,然后开始使用新的AMI id的另一个实例。
最有可能的是,你已经把你的github代码放在错误的目录(即不是nginx doc根目录),所以nginx默认为它默认的问候语。
这听起来像你使用静态HTML页面,所以这是非常简单的。
只需粘贴你的/etc/nginx/nginx.conf(和任何包含的conf文件)。
编辑::更仔细地阅读通过这个问题后,它听起来像有一个初始化过程,将您的nginx conf重置为默认configuration。 再次,粘贴您的conf文件,我们可以进一步帮助。 当你重新启动,你有没有注意到这个文件的变化? 什么时间戳? 和开机一样?
编辑2:尝试使用不同的ami,如官方centos 6.4 ami
它不会在重新启动时发生,只有当我创build一个新的EC2并使用AMI。
或者至less给我们更多关于你正在启动的细节。 很有可能,这种奇怪的行为不会发生在官方的AMI上
这是我的猜测:Nginx的默认网站已经到位并取代你的网站。 这里有几件事要尝试: