CentOS7.4安装nginx1.12.1

安装

添加源,可以参考官网安装说明

vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

安装

yum install nginx

启动

systemctl start nginx

设置

开机自启动

systemctl enable nginx

防火墙设置

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --reload

使用nobody用户运行

vi /etc/nginx/nginx.conf
user nobody;

重载生效

nginx -s reload

新建网站

新建网站目录

mkdir -p /www/domain

新建网站配置

vi /etc/nginx/conf.d/domain.conf
server {
    listen 80;
    server_name domain;
    root /www/domain;
    index index.html index.htm index.php;
    location / {
    	try_files $uri $uri/ /index.php;
    }
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

注意:目录/etc/nginx/conf.d/default.conf是默认网站,使用的server_name是localhost:80。

相关文章

linux下开机自启: 在/etc/init.d目录下新建文件elasticsear...
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以...
最简单的查看方法可以使用ls -ll、ls-lh命令进行查看,当使用...
ASP.NET Core应用程序发布linux在shell中运行是正常的。可一...
设置时区(CentOS 7) 先执行命令timedatectl status|grep &...
vim /etc/sysconfig/network-scripts/ifcfg-eth0 B...