Ubuntu安装Nginx

其实其他Linux安装都是差不多的可能稍微目录不一样 需要注意的是要改Apache为另外的端口例如PHP
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

其实其他Linux安装都是差不多的 可能稍微目录不一样

 

需要注意的是要改Apache为另外的端口例如81  不然跑2个80会打架的。

 

1.安装nginx
运行:

sudo apt-get intsall nginx

 

2.启动nginx

运行:

sudo /etc/init.d/nginx start

 

3.查看网页

浏览器里输入http://localhost/

提示  Welcome to nginx说明安装成功了!

 

提示:在ubuntu11.04中nginx 默认网站目录为

/usr/share/nginx/www

 

Ubuntu安装Nginx

 

这个是被我改了HTML的。

 

不要高兴的太早,要想支持PHP还要经历一番折腾。

 

4.安装PHP5
apt-get install php5-fpm
PHP – FPM是一个守护进程(与初始化脚本 / etc/init.d/php5-fpm )运行FastCGI服务器上的端口 9000 。

5.nginx的配置
配置文件/etc/nginx/nginx.conf
vi /etc/nginx/nginx.conf
你可以通过http://wiki.codemongers.com/NginxFullExamplehttp://wiki.codemongers.com/NginxFullExample2网址了解更多配置信息。
增加工作进程,可选,可以不修改
worker_processes 5;
keepalive_timeout 2;
默认虚拟主机配置文件地址/etc/nginx/sites-available/default

CODE:
vi /etc/nginx/sites-available/default

server {

listen 80; ## listen for ipv4; this line is default and implied

listen [::]:80 default ipv6only=on; ## listen for ipv6

root /usr/share/nginx/www;

index index.php index.html index.htm;

# Make site accessible from http://localhost/

server_name _;

location / {

# First attempt to serve request as file, then

# as directory, then fall back to index.html

try_files $uri $uri/ /index.html;

}

location /doc {

root /usr/share;

autoindex on;

allow 127.0.0.1;

deny all;

}

location /images {

root /usr/share;

autoindex off;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/www;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ /.php$ {

# proxy_pass [url]http://127.0.0.1[/url];

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ /.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

# deny access to .htaccess files, if Apache’s document root

# concurs with nginx’s one

#

location ~ //.ht {

deny all;

}

}

 

 6.重启命令

ngnix重新加载一下配置
nginx -s reload
最后重启生效
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm restart

Ubuntu安装Nginx

本文来源21aspnet,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/2355

发表评论