大佬教程收集整理的这篇文章主要介绍了CentOS 7.2 安装Nginx服务,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
# install from EPEL
[root@linuxprobe~]# yum --enablerepo=epel -y install Nginx
# 基础设置
[root@linuxprobe~]# vi /etc/Nginx/Nginx.conf
# line 40: change hostname
server_name linuxprobe.org;
[root@linuxprobe ~]# systemctl start Nginx
[root@linuxprobe ~]# systemctl enable Nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/Nginx.service to /usr/lib/systemd/system/Nginx.service.
[root@linuxprobe ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain linuxprobe.org
10.1.1.56 vdevops.com
# 开启防火墙
[root@linuxprobe ~]# firewall-cmd --add-service=http --peRMANent
success
[root@linuxprobe ~]# firewall-cmd --reload
success
[root@linuxprobe ~]# vi /etc/Nginx/conf.d/linuxcool.com.conf
# create new
server {
listen 80;
server_name linuxcool.com;
@R_772_5352@n / {
root /usr/share/Nginx/linuxcool;
index index.html index.htm;
}
}
[root@linuxprobe ~]# mkdir /usr/share/Nginx/linuxcool
[root@linuxprobe w ~]# systemctl restart Nginx
[root@linuxprobe ~]# vi /usr/share/Nginx/virtual.host/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx LinuxCool Test Page
</div>
</body>
</html>
[root@linuxprobe ~]# vi /etc/Nginx/Nginx.conf
# add into "server" section
@R_772_5352@n ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/public_html$2;
index index.html index.htm;
autoindex on;
}
[root@linuxprobe ~]# systemctl restart Nginx
# 切到普通用户
[wang@linuxprobe~]$ chmod 711 /home/cent
[wang@linuxprobe~]$ @H_192_56@mkdir ~/public_html [wang@linuxprobe~]$ chmod 755 ~/public_html
[wang@linuxprobe~]$ vi ~/public_html/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx UserDir Test Page
</div> </body>
</html>
[root@linuxprobe~]# vi /etc/Nginx/Nginx.conf
# add into "server" section
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl;
server_name linuxprobe.org;
root /usr/share/Nginx/html;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE+RSAGCM:ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:!aNULL!eNull:!EXPORT:!DES:!3DES:!@H_665_248@mD5:!DSS;
ssl_certificate /etc/pki/tls/certs/server.crt;
ssl_certificate_key /etc/pki/tls/certs/server.key;
[root@linuxprobe~]# systemctl restart Nginx
[root@linuxprobe~]# firewall-cmd --add-service=https --peRMANent
success
[root@linuxprobe~]# firewall-cmd --reload
success
@H_842_301@Nginx 设置访问认证
# 以auth_basic目录为例
[root@linuxprobe~]# yum -y install httpd-tools
[root@linuxprobe~]# vi /etc/Nginx/Nginx.conf
# add into "server" section
@R_772_5352@n /auth_basic {
auth_basic "Basic Auth";
auth_basic_user_file "/etc/Nginx/.htpasswd";
}
[root@linuxprobe~]# htpasswd -c /etc/Nginx/.htpasswd wang
New password: # set password
Re-type new password:
Adding password for user wang
[root@www ~]# systemctl restart Nginx
# 创建目录及测试页面
[root@linuxprobe ~]# mkdir /usr/share/Nginx/html/auth_basic
[root@linuxprobe ~]# vim /usr/share/Nginx/html/auth_basic/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx UserDir Test Page
</div>
</body>
</html>
[root@linuxprobe ~]# vi /etc/Nginx/Nginx.conf
# change like follows in "server" section
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name linuxprobe.org;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-ForWARDed-For $proxy_add_x_forWARDed_for;
proxy_set_header Host $http_host;
@R_772_5352@n / {
proxy_pass http://vdevops.org/;
}
}
[root@linuxprobe ~]# systemctl restart Nginx
[root@vdevops~]# vi /etc/httpd/conf/httpd.conf
# line 196: change
LogFormat "\"%{X-ForWARDed-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
[root@vdevops~]# systemctl restart httpd
# 通过elinks(模拟浏览器访问)访问验证
[root@localhost ~]# yum -y install elinks
[root@linuxprobe ~]# elinks http://linuxprobe.org/
[root@linuxprobe ~]# yum --enablerepo=epel -y install PHP PHP-mbString PHP-pear PHP-fpm
[root@linuxprobe ~]# vi /etc/PHP-fpm.d/www.conf
# line 39: change
user = Nginx
# line 41: change
group = Nginx
[root@linuxprobe ~]# systemctl start PHP-fpm
[root@linuxprobe ~]# systemctl enable PHP-fpm
[root@linuxprobe ~]# vi /etc/Nginx/Nginx.conf
# add into "server" section
@R_772_5352@n ~ \.PHP$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILename $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
[root@linuxprobe ~]# systemctl restart Nginx
[root@www ~]# echo "<?PHP PHPinfo() ?>" > /usr/share/Nginx/html/info.PHP
以上是大佬教程为你收集整理的CentOS 7.2 安装Nginx服务全部内容,希望文章能够帮你解决CentOS 7.2 安装Nginx服务所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。