Centos 7 安装 Nginx

Step One—Add Nginx Repository

第一步,添加Nginx 库

sudo yum install epel-release

Step Two—Install Nginx

第二步安装

sudo yum install nginx

输入Y

Step Three—Start Nginx

第三步运行

Nginx does not start on its own. To get Nginx running, type:

sudo systemctl start nginx

如果没什么问题就可以输入网站地址测试。成功的话就见到下面的的图。

因为我同时安装了Apache,所以80端口被占用了。启动的时候报错

Unit start.service could not be found.
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 三 2018-01-17 18:34:14 CST; 10s ago
  Process: 4237 ExecStart=/usr/sbin/nginx (code=exited, status=1/FAILURE)
  Process: 4234 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 4233 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

1月 17 18:34:12 VM_66_141_centos nginx[4237]: nginx: [emerg] bind() to 0.0....)
1月 17 18:34:12 VM_66_141_centos nginx[4237]: nginx: [emerg] bind() to 0.0....)
1月 17 18:34:13 VM_66_141_centos nginx[4237]: nginx: [emerg] bind() to 0.0....)
1月 17 18:34:13 VM_66_141_centos nginx[4237]: nginx: [emerg] bind() to 0.0....)
1月 17 18:34:14 VM_66_141_centos nginx[4237]: nginx: [emerg] bind() to 0.0....)
1月 17 18:34:14 VM_66_141_centos systemd[1]: nginx.service: control process...1
1月 17 18:34:14 VM_66_141_centos nginx[4237]: nginx: [emerg] still could no...)
1月 17 18:34:14 VM_66_141_centos systemd[1]: Failed to start The nginx HTTP....
1月 17 18:34:14 VM_66_141_centos systemd[1]: Unit nginx.service entered fai....
1月 17 18:34:14 VM_66_141_centos systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

这个时候修改配置文件/etc/nginx/nginx.conf

server {
        listen       8088 default_server;
        listen       [::]:8088 default_server;

然后执行下面命令测试一下

nginx -t -c /etc/nginx/nginx.conf

执行下面命令加入启动项

sudo systemctl enable nginx

Over.

发表评论

邮箱地址不会被公开。