openEuler安装nginx
环境:
OS:openEuler 22 sp4
nginx:1.21.5
1.安装
dnf install nginx
2.启动
systemctl start nginx
systemctl enable nginx
systemctl status nginx
默认的配置文件路径
/etc/nginx/nginx.conf
3.创建普通用户
useradd -m hxl -s /bin/bash
passwd hxl
4.修改配置文件以普通用户启动同时调整其他参数
vi /etc/nginx/nginx.conf
user hxl;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 65535;
multi_accept on;
use epoll;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
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 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
log_format main '{"@timestamp":"$time_iso8601","server":"$hostname","clientip":"$remote_addr","xff":"$http_x_forwarded_for","domain":"$host","url":"$uri","referer
":"$http_referer","args":"$args","upstreamtime":"$upstream_response_time","resptime":"$request_time","method":"$request_method","status":"$status","size":"$body_bytes
_sent","req_len":"$request_length","protocol":"$server_protocol","upstreamhost":"$upstream_addr","useragent":"$http_user_agent","conns":"$connection","from":"nginx-dc
"}';
access_log /var/log/nginx/access.log;
##
# Gzip Settings
##
keepalive_timeout 300;
send_timeout 300;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
client_body_buffer_size 512k;
client_header_buffer_size 4k;
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
5.重启
查看配置文件是否正确
[root@localhost conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
systemctl restart nginx
systemctl status nginx
[root@localhost conf.d]# ps -ef|grep nginx
root 10189 1 0 15:34 ? 00:00:00 nginx: master process /usr/sbin/nginx
hxl 10190 10189 0 15:34 ? 00:00:00 nginx: worker process
root 10196 2127 0 15:34 pts/2 00:00:00 grep --color=auto nginx
5.修改项目目录权限
# 归属改为 hxl 用户组
chown -R hxl:hxl /usr/share/nginx/html
日志目录
chown -R hxl:hxl /var/log/nginx
chmod -R 755 /var/log/nginx
虚拟主机配置目录
chown -R hxl:hxl /etc/nginx/conf.d
6.配置默认访问
su - hxl
vi /etc/nginx/conf.d/default.conf
填写如下内容
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
index index.html index.htm;
}
切回到root账号
# 语法检查
nginx -t
# 平滑重载
systemctl reload nginx
7.本地访问
curl 127.0.0.1
或是浏览器访问
http://192.168.1.107:80
浙公网安备 33010602011771号