Nginx 的使用
程序员文章站
2022-06-03 16:22:11
...
0 下载安装
sudo sudo agt-get install nginx
1,修改配置文件
sudo vim /etc/nginx/sites-available/default
server {
listen 80; ## listen for ipv4
#listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
root /home/jimmy/web;
index index.html index.htm;
autoindex on;
}
2,安装nginx时,系统会为运行该软件添加一用户和组www-data
/etc/nginx/nginx.conf
3,给予web目录相应权限
sudo chown -R www-data:www-data /home/wanghao/web
sudo chmod 777 /home/jimmy/web
4,启动Nginx
jimmy@jimmy:~$ /etc/init.d/nginx stats
Usage: nginx {start|stop|restart|reload|force-reload|status|configtest}
jimmy@jimmy:~$ sudo /etc/init.d/nginx stop
[sudo] password for jimmy:
Stopping nginx: nginx.
jimmy@jimmy:~$ sudo /etc/init.d/nginx start
假设:/home/jimmy/web/demo.htm
则访问demo.htm的url如下:
http://localhost/demo.htm or http://10.36.64.159/demo.htm
sudo sudo agt-get install nginx
1,修改配置文件
sudo vim /etc/nginx/sites-available/default
server {
listen 80; ## listen for ipv4
#listen [::]:80 default ipv6only=on; ## listen for ipv6
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
location / {
root /home/jimmy/web;
index index.html index.htm;
autoindex on;
}
2,安装nginx时,系统会为运行该软件添加一用户和组www-data
/etc/nginx/nginx.conf
3,给予web目录相应权限
sudo chown -R www-data:www-data /home/wanghao/web
sudo chmod 777 /home/jimmy/web
4,启动Nginx
jimmy@jimmy:~$ /etc/init.d/nginx stats
Usage: nginx {start|stop|restart|reload|force-reload|status|configtest}
jimmy@jimmy:~$ sudo /etc/init.d/nginx stop
[sudo] password for jimmy:
Stopping nginx: nginx.
jimmy@jimmy:~$ sudo /etc/init.d/nginx start
假设:/home/jimmy/web/demo.htm
则访问demo.htm的url如下:
http://localhost/demo.htm or http://10.36.64.159/demo.htm