安装
添加源,可以参考官网安装说明
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。