簡體   English   中英

使用 ansible 啟動 nginx web 服務器:localhost:8080 沒有響應

[英]Using ansible to launch nginx web server: localhost:8080 not responding

我正在通過閱讀 Lorin Hochstein 的偉大的Ansible Up and Running一書來試驗 Ansible。

在帶有 Ansible 的 Ubuntu 16.04 機器上,我現在正在嘗試運行web-tls playbook。

例如,我創建了一個web-notls.yml文件,並將其放入playbook目錄:

    - name: Configure webserver with nginx
hosts: webservers
sudo: True
tasks:
- name: install nginx
apt: name=nginx update_cache=yes
- name: copy nginx config file
copy: src=files/nginx.conf dest=/etc/nginx/sites-available/default
- name: enable configuration
file: >
dest=/etc/nginx/sites-enabled/default
src=/etc/nginx/sites-available/default
state=link
- name: copy index.html
template: src=templates/index.html.j2 dest=/usr/share/nginx/html/index.html
mode=0644
- name: restart nginx
service: name=nginx state=restarted

我還指定了一個nginx.conf文件,並將其放在playbooks/files/nginx.conf目錄中:

   server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
}

我還創建了 hosts 文件來輕松訪問 Vagrant 機器,並創建了一個 Web 自定義主頁,以便在訪問網頁后查看消息。

我修改了Vagrantfile以包含以下代碼:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 443, host: 8443
end

這個改動后,我本地機器上的8080端口應該轉發到Vagrant機器的80端口,我本地機器上的8443端口應該轉發到vagrant機器上的ort 443: 8080端口轉發架構嘗試運行時劇本作者:

$ ansible-playbook web-notls.yml

輸出是:

luigi@luigi-H87-HD3:~/playbooks$ ansible-playbook web-notls.yml 
[DEPRECATION WARNING]: [defaults]hostfile option, The key is misleading as it can also be a list of 
hosts, a directory or a list of paths , use [defaults] inventory=/path/to/file|dir instead. This 
feature will be removed in version 2.8. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
[DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method
 is 'sudo' (default). This feature will be removed in version 2.6. Deprecation warnings can be 
disabled by setting deprecation_warnings=False in ansible.cfg.

PLAY [Configure webserver with nginx] ***************************************************************

TASK [Gathering Facts] ******************************************************************************
ok: [testserver]

TASK [install nginx] ********************************************************************************
ok: [testserver]

TASK [copy nginx config file] ***********************************************************************
ok: [testserver]

TASK [enable configuration] *************************************************************************
ok: [testserver]

TASK [copy index.html] ******************************************************************************
ok: [testserver]

TASK [restart nginx] ********************************************************************************
changed: [testserver]

PLAY RECAP ******************************************************************************************
testserver                 : ok=6    changed=1    unreachable=0    failed=0 

到目前為止似乎沒有錯誤。 我現在試圖通過瀏覽器在我的本地機器上打開localhost:8080地址(我也嘗試做一個 vagrant ssh 並嘗試 curl localhost:8080 沒有成功)但我沒有收到任何結果。 我究竟做錯了什么 ?

先感謝您!

乍一看, anisble 輸出沒有錯誤,所以我認為腳本完成了它的工作。 錯誤似乎是您應該查看localhost:80而不是localhost:8080

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM