前端之家收集整理的这篇文章主要介绍了
CentOS 7.2 安装Nginx服务,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
[root@linuxprobe~]
[root@linuxprobe~]
server_name linuxprobe.org;
[root@linuxprobe ~]
[root@linuxprobe ~]
Created symlink from /etc/systemd/system/multi-user.target.wants/Nginx.service to /usr/lib/systemd/system/Nginx.service.
[root@linuxprobe ~]
127.0.0.1 localhost localhost.localdomain linuxprobe.org
10.1.1.56 vdevops.com
[root@linuxprobe ~]
success
[root@linuxprobe ~]
success
- 客户端设置hosts,从浏览器访问linuxprobe.org
虚拟主机设置
[root@linuxprobe ~]
server {
listen 80;
server_name linuxcool.com;
location / {
root /usr/share/Nginx/linuxcool;
index index.html index.htm;
}
}
[root@linuxprobe ~]
[root@linuxprobe w ~]
[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 ~]
location ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/public_html$2;
index index.html index.htm;
autoindex on;
}
[root@linuxprobe ~]
[wang@linuxprobe~]$ chmod 711 /home/cent
[wang@linuxprobe~]$ 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~]
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:!MD5:!DSS;
ssl_certificate /etc/pki/tls/certs/server.crt;
ssl_certificate_key /etc/pki/tls/certs/server.key;
[root@linuxprobe~]
[root@linuxprobe~]
success
[root@linuxprobe~]
success
@H_530_
301@
Nginx 设置访问认证
[root@linuxprobe~]
[root@linuxprobe~]
location /auth_basic {
auth_basic "Basic Auth";
auth_basic_user_file "/etc/Nginx/.htpasswd";
}
[root@linuxprobe~]
New password:
Re-type new password:
Adding password for user wang
[root@www ~]
[root@linuxprobe ~]
[root@linuxprobe ~]
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Nginx UserDir Test Page
</div>
</body>
</html>
- 配置通过http方式,Nginx的80端口转发到后端apache的80端口
[root@linuxprobe ~]
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;
location / {
proxy_pass http://vdevops.org/;
}
}
[root@linuxprobe ~]
[root@vdevops~]
LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
[root@vdevops~]
[root@localhost ~]
[root@linuxprobe ~]
[root@linuxprobe ~]
- 配置 Configure PHP-FPM and Ngin
[root@linuxprobe ~]
user = Nginx
group = Nginx
[root@linuxprobe ~]
[root@linuxprobe ~]
[root@linuxprobe ~]
location ~ \.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 ~]
[root@www ~]# echo "<?PHP PHPinfo() ?>" > /usr/share/Nginx/html/info.PHP