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 权限

 

完成。

获取更多帮主请关注小程序

 

你可能感兴趣的:(工具,linux,nginx,centos)