Nginx不显示自定义根文件夹的文件

时间:2018-03-17 12:50:45

标签: amazon-web-services nginx default

我在nginx EC2实例前使用经典的负载均衡器,并将我站点的A记录指向负载均衡器。我正在获取默认的nginx页面,即使我的根指向自定义文件夹/ home / ubuntu / mydomain / pulic。

当我更改html文件夹下的index.html文件内容时,我能够看到更改。但是,我不知道这个页面指向的位置。我尝试修改/usr/local/nginx/conf/nginx.conf和/usr/src/nginx-1.13.6/conf/nginx.conf中的根路径。但是不起作用(没有看到变化)。

任何人都可以帮我吗?用不同的方式用Google搜索,没有找到任何帮助。

我正在寻找的是负载均衡器和EC2实例之间的安全HTTPS连接。

注意:我手动安装了nginx而没有使用apt-get。

1 个答案:

答案 0 :(得分:0)

如果您运行命令nginx -t,它应该输出正在使用的配置文件的位置:

root@myhost:~# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

如果您查看该文件,您将找到主http配置 - 服务器的全局配置。您可以在此文件中找到配置的默认站点,也可以在另一个文件中使用include语句引用它,例如include /etc/nginx/conf.d/*.conf;

我建议不要编辑默认网站,而是在nginx.conf的主server部分中添加额外的http块,或者更好地在包含的单独.conf文件中添加进入主配置文件,如下所示:include /path/to/my/example.com.conf。这样做意味着通过浏览器访问服务器的IP将不会显示您的网站(您应该使用空白文件替换默认文档)。

如果您想托管https://www.example.com,您可以创建一个配置文件,例如/path/to/www.example.com.conf,其中包含:

# main https://www.example.com config
server {
  server_name www.example.com;
  listen 443 ssl;

  #public and private keys for your ssl certificate. 
  ssl_certificate /path/to/www.example.com/ssl/fullchain.pem;
  ssl_certificate_key /path/to/www.example.com/ssl/privkey.pem;
  # there are common sense values for SSL
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:SSL:10m;
  server_tokens off;

  # you can generate this file from the shell:  openssl dhparam -out /etc/nginx/dhparam.pem 2048
  #ssl_dhparam /etc/nginx/dhparam.pem;

  # if its just ELB you can restrict this to just TLSv1.2
  #ssl_protocols TLSv1.1 TLSv1.2;

  # The following list should work and only use more modern ciphers, but do your research/trial and error
  # on which ciphers your ELB can use and pick the strongest.
  ##ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';


  #Adding this header will force browsers to only ever request HTTPS from your site.
  ##add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";


  #set your web root here:
  root /path/to/www.example.com/httpdocs;

  #default document
  index index.html;

}

# redirect HTTP www.example.com to HTTPS for cannonical URL
server {
  listen 80;
  server_name www.example.com;
  return 301 https://www.example.com$request_uri;
}

然后在主要的nginx.conf文件中,在http部分内添加以下行:

include /path/to/www.example.com.conf;

再次运行nginx -t以检查更改是否有效,然后在浏览器中进行测试。