Nginx安装
阿里云cetos7已经默认添加了nginx的yum源,可以通过yum search nginx
确认。
如果没有,则可以通过运行rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
进行添加。
命令
123 |
systemctl start nginx.service # 启动nginx服务 systemctl stop nginx.service # 关闭 systemctl enable nginx.service # 开机 |
配置
由于我开启了8001的安全组规则,所以我使用8001端口来演示展示一个Hello Nginx页面
由于是使用yum安装的,所以让我们看看nginx安装到了哪?
1 |
whereis nginx # nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz /usr/share/man/man3/nginx.3pm.gz |
然后我发现/etc/nginx
下面有配置文件nginx.conf
,应该就是它了, 让我们看下文件内容cat nginx.conf
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
# For more information on configuration, see:# * Official English Documentation: http://nginx.org/en/docs/# * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf; events { worker_connections 1024;} http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; 大专栏 Cetos7安装nginx三两事 # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } # Settings for a TLS enabled server.## server {# listen 443 ssl http2 default_server;# listen [::]:443 ssl http2 default_server;# server_name _;# root /usr/share/nginx/html;## ssl_certificate "/etc/pki/nginx/server.crt";# ssl_certificate_key "/etc/pki/nginx/private/server.key";# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 10m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;## # Load configuration files for the default server block.# include /etc/nginx/default.d/*.conf;## location / {# }## error_page 404 /404.html;# location = /40x.html {# }## error_page 500 502 503 504 /50x.html;# location = /50x.html {# }# } } |
让我们增加一个server配置, 页面在~/nginx-demo/index.html
:
1234567891011121314151617181920 |
server { listen 8001; listen [::]:8001; server_name _; root ~/nginx-demo; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { }} |
让我们打开浏览器访问页面看看.
发现页面403,让我们看看怎么了? 发现是我们所在的文件夹没有读取权限,通过运行chmod 755 /root
即可(/root
就是~
)。
这样我们就可以访问页面了。??
1234 |
nginx #运行配置$ nginx -s reload # 重新加载配置文件$ nginx -s reopen # 重启$ nginx -s stop # 关闭 |
原文地址:https://www.cnblogs.com/dajunjun/p/11712937.html
时间: 2024-09-28 15:55:46