Tag Archives: nginx

[Solved] nginx Error: directory index of “/home/www/hexo/” is forbidden

Note: Recently, when setting up hexo, I finished all the work. I found that nginx reported 403 Forbidden. I checked the log of nginx

Log information is recorded as follows:

*481 directory index of “/home/www/hexo/” is forbidden~~~~~~

Solution: go to the configuration file nginx.conf in the nginx conf directory Conf plus configure autoindex on; Automatic indexing

Restart ngxin

How to Solve nginx Install Error in Mac

Error Messages:
==> Installing dependencies for nginx: pcre
==> Installing nginx dependency: pcre
error: could not lock config file .git/config: Permission denied
Error: Command failed with exit 255: git
Solution: sudo chown -R $(whoami):admin /usr/local/* && sudo chmod -R g+rwx /usr/local/*

Nginx normal user startup configuration error: && springboot-swagger & Unable to infer base url

2022/01/04 08:50:55 [crit] 8715#8715: *107201 mkdir() “/var/cache/nginx/proxy_temp/3” failed (13: Permission denied) while reading upstream, client: 192.168.181.166, server: localhost, request: “GET /prod-api/swagger-ui/swagger-ui-standalone-preset.js?v=3.0.0 HTTP/1.1”, upstream: “http://[::1]:8090/swagger-ui/swagger-ui-standalone-preset.js?v=3.0.0”, host: “hostname:9000”, referrer: “http://hostname:9000/prod-api/swagger-ui/index.html”. 

Solution:

Looking at the nginx log, there is no /var/cache/nginx/proxy/temp permission. Authorize it.
sudo chmod a+w /var/cache/nginx/proxy_temp -R

How to Install nginx yum:

Add repo of nginx:

echo '[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/x86_64
gpgcheck=0
enabled=1' > /etc/yum.repos.d/nginx.repo

install

yum update
yum install nginx

Did you install the latest version of nginx directly?
log]$ whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz

Then you need to configure the normal user path of nginx. Create the relevant directory and copy the configuration file. Authorize proxy_temp. As above.
log]$ mkdir -p /data/nginx/log /data/nginx/run  /data/nginx/conf.d
log]$ cp /etc/nginx/nginx.conf /data/nginx/
log]$ cp /etc/nginx/conf.d/default.conf /data/nginx/conf.d/
sudo chmod a+w /var/cache/nginx/proxy_temp -R
log]$ vi /data/nginx/nginx.conf

#user  nobody;
worker_processes  auto;

error_log  /data/nginx/log/error.log notice;
pid        /data/nginx/run/nginx.pid;


events {
    use epoll;
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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  /data/nginx/log/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /data/nginx/conf.d/*.conf;
}

Hope this article will help you.

nginx Server Start Error: nginx: [emerg] open() “/var/run/nginx/nginx.pid” failed (Linux Restart)

Question:

After Linux restarts, an error is reported when starting the nginx server

Solution:

1. Use the command CD/usr/local/nginx/conf to enter the specified directory

2. Use the command VI nginx Conf modify the configuration file # and remove the # number in the figure

3. Change to PID/usr/local/nginx/logs/nginx.pid;

4. Use the command MKDIR/usr/local/nginx/logs to create a directory

5. Start nginx service

How to Solve Nginx error: 403 Forbidden

Today, I tested nginx access on my virtual machine, and the results were 403 Forbidden

First check whether there is a missing index in the nginx configuration file HTML or index PHP files, files are normal

Check the SELinux status of the server. The configuration file/etc/SELinux/config and SELinux = disabled are also correct

Then check the log information:/usr/local/nginx/logs/error log

The display is caused by permission problems. View the main configuration file of nginx/usr/local/nginx/conf/nginx conf

After changing the user to root, restart nginx # systemctl restart nginx Service access is effective

Summary: there are three common situations causing nginx access error 403 Forbidden: lack of index file, permission problem and SELinux status

It can be successfully modified according to specific problems.

[Solved] Nginx Error: could not build server_names_hash, you should increase server_names_hash_bucket_size

I’m setting up a new server. The HTTP server I selected is nginx. I already have 2 domains. It works normally, but when I try to add the above domain and start the server, the following error is reported

nginx: [emerg] could not build server_names_hash, you should increase server_nam 
es_hash_bucket_size: 32

Directly in nginx Add the following code to HTTP of conf

server_names_hash_bucket_size  512;

[Solved] Nginx Startup Error: nginx: [alert] could not open error log file: open() “/usr/local/nginx/logs/error.log“ failed

Nginx Startup Error: nginx: [alert] could not open error log file: open() “/usr/local/nginx/logs/error.log“ failed

nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
2021/12/06 20:12:14 [emerg] 466858#0: mkdir() "/usr/local/nginx/client_body_temp" failed (2: No such file or directory)

Error Description: the error path is/use/local. It is found that the file location is inconsistent

Solution: move Nginx to local and start it again

PHP FPM and Nginx start normally, page 502 Error [How to Solve]

PHP FPM and nginx are started normally, and page 502 is solved

Background: for the newly installed system, after manually installing PHP, nginx and PHP FPM modules, deploy a PHP project locally. When running, it is found that only nginx version page displays 502

The troubleshooting process is as follows, which is briefly recorded:

Check the startup of PHP FPM and nginx:

# Check if php-fpm and nginx are up
ps -ef|grep php-fpm
ps -ef|grep nginx

The result is: both are up and running

View the nginx log information at the time of the request:

# First, we looked at the location of the nginx runtime logs.
find/-name nginx.conf # Find the nginx configuration file and see where the error.log is stored
# View the error.log information as follows.
*58 connect() failed (111: Connection refused) while connecting to upstream

Troubleshooting results:

PHP FPM and nginx are all started normally, so it is not the reason why PHP FPM is not started. Continue to check and find that:

There are two ways to link nginx and php.
1. fastcgi_pass 127.0.0.1:9000;
2. fastcgi_pass unix:/run/php/php7.0-fpm.sock;


You have to go to the php fpm configuration file to see how this works
/etc/php/7.0/fpm/pool.d/www.conf

If Listen is the port, write 127.0.0.1:9000;
If it's a path, the nginx configuration file should learn the path as well.unix:/run/php/php7.0-fpm.sock;

Perfect solution: check the www.conf configuration file, and the path is after listen, so modify the nginx configuration file of the project:

### # fastcgi_pass   127.0.0.1:9000;  # Comment out this port and replace it with the following path format
fastcgi_pass unix:/run/php/php7.3-fpm.sock; # fastcgi_pass to the address of phm.sock on the local machine

Nginx Error: Nginx 403 error:directory index of “xxx“ is forbidden

After deploying the nginx server, enter the IP address and port number and return 403 Forbidden

Check the log error.log and find that the error message is:

directory index of “xxx” is forbidden

Where XXX is the root directory specified in/etc/nginx/nginx.conf.

Root cause of error: when accessing directly using IP address and port number, you need to specify index. If it is not specified, this error occurs.

At this time, you can add configurations in nginx/nginx.conf:
autoindex on# Automatic indexing

In this way, when accessed again, all resource indexes will be listed.

[note] after modifying nginx.conf, remember to restart the service to take effect.