CentOS下安裝nginx以及連接埠配置教程

來源:互聯網
上載者:User

在nginx官網上找到支援資訊:

Currently, nginx packages are available for the following distributions and versions:

RHEL/CentOS:

Version Supported Platforms
5.x x86_64, i386
6.x x86_64, i386
7.x x86_64

Debian:

Version Codename Supported Platforms
6.x squeeze x86_64, i386
7.x wheezy x86_64, i386
8.x jessie x86_64, i386

Ubuntu:

Version Codename Supported Platforms
10.04 lucid x86_64, i386
12.04 precise x86_64, i386
14.04 trusty x86_64, i386, aarch64/arm64
14.10 utopic x86_64, i386

SLES:


To enable automatic updates of Linux packages set up the yum repository for the RHEL/CentOS distributions, the apt repository for the Debian/Ubuntu distributions, or the zypper repository for SLES.

看到是支援CentOS通過yum安裝的,直接上命令:

# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
 
# yum -y install nginx
就成功安裝了,然後開啟服務,報連接埠衝突。(由於事先安裝了apache佔用了80連接埠)


# service nginx start

Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[FAILED]

於是找到nginx的設定檔


# vim /etc/nginx/nginx.conf

看到裡面有一句”include /etc/nginx/conf.d/*.conf;”,於是又找到/etc/nginx/conf.d/default.conf這個檔案

vim /etc/nginx/conf.d/default.conf

開啟後把listen 80改成listen 8080,然後啟動nginx。

1
# service nginx restart
開啟瀏覽器 輸入http://localhost:8080/,就可以看到出現如下內容。

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.