centos 7 安装配置nginx

前端之家收集整理的这篇文章主要介绍了centos 7 安装配置nginx前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

安装

1: sudo yum update

2: sudo yum install Nginx

启动

sudo service Nginx start

配置(多个并行配置)

1,添加用户权限www-data

/usr/sbin/groupadd -f www-data
/usr/sbin/useradd -g www-data www-data

2,修改Nginx.conf

sudo vim /etc/Nginx/Nginx.conf

Nginx.conf 内容如下

user www-data;
worker_processes auto;
pid /run/Nginx.pid;

events {
	worker_connections 768;
	# multi_accept on;
}

http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/Nginx/mime.types;
	default_type application/octet-stream;

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3,ref: POODLE
	ssl_prefer_server_ciphers on;

	##
	# Logging Settings
	##

	access_log /var/log/Nginx/access.log;
	error_log /var/log/Nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	include /etc/Nginx/conf.d/*.conf;
	include /etc/Nginx/sites-enabled/*;
}

3:创建文件

cd /etc/Nginx/
sudo mkdir sites-available
sudo mkdir sites-enabled

4:进入sites-available 文件

sudo vim default_80

default_80内容如下:

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

        root /var/www/html;

        # Add index.PHP to the list if you are using PHP
        index index.html index.htm index.Nginx-debian.html index.PHP;

        server_name _;

        location / {
                # First attempt to serve request as file,then
                # as directory,then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
}

5:添加链接

cd ../sites-enabled
sudo ln -s ../sites-available/default_80 default_80

6:重启Nginx

sudo service reload

7:创建目录:/var/www/html

并给html设置www-data 权限


完成。

猜你在找的CentOS相关文章